BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Config Implicit Object in JSP with examples

Last Updated: July 27, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

In this tutorial, you will learn config implicit object in JSP. It is an instance of javax.servlet.ServletConfig. The JSP config implicit object is used for getting configuration information for a particular JSP page. Using application implicit object we can get application-wide initialization parameters, however using Config we can  get initialization parameters of an individual servlet mapping.

Methods of Config Implicit Object

  1. String getInitParameter(String name): It returns the value of Initialization parameter for a given parameter name.
    <web-app>
    …
    <context-param>
    <param-name>parameter1</param-name>
    <param-value>ValueOfParameter1</param-value>
    </context-param>
    </web-app>

    This is the web.xml file

    String s=application.getInitParameter(“parameter1”);

    The value of s will be “ValueOfParameter1”. Still confused where did it come from? See the param-value tag in he above web.xml file.

  2. Enumeration getInitParameterNames(): Returns enumeration of Initialization parameters.
  3. ServletContext getServletContext(): This method returns a reference to the Servlet context.
  4. String getServletName(): It returns the name of the servlet which we define in the web.xml file inside <servlet-name> tag.

JSP config implicit object Example

Following is the web.xml file. In this file, servlet name and mappings are defined. We can fetch these details using config implicit object. In this example, we are demonstrating how to fetch these details using config implicit object.
web.xml

<web-app>
<servlet> 
<servlet-name>BeginnersBookServlet</servlet-name> 
<jsp-file>/index.jsp</jsp-file> 
</servlet> 

<servlet-mapping> 
<servlet-name>BeginnersBookServlet</servlet-name> 
<url-pattern>/index</url-pattern> 
</servlet-mapping> 
</web-app>

index.jsp
In this JSP page we are calling getServletName() method of config object for fetching the servlet name from web.xml file.

<html>
<head> <title> Config Implicit Object</title>
</head>
<body>
<% 
String sname=config.getServletName(); 
out.print("Servlet Name is: "+sname); 
%>
</body>
</html>

Output: This is the output screen for the above JSP page. In the web.xml file, we have defined the servlet name as “BeginnersBookServlet”. In the index.jsp page, we are fetching the servlet name using config implicit object.  The fetched value then displayed on the screen using out.print() method.
Config Implicit Object in JSP

❮ JSP responseJSP application ❯

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Application Implicit Object in JSP with examples
  3. Java Server Pages (JSP) Life Cycle
  4. pageContext Implicit Object in JSP with examples
  5. Solution – The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Medha says

    January 22, 2017 at 5:18 PM

    Hi, Let’s say we have multiple servlet mappings in web.xml(as it is usually the case), how would you fetch that particular servlet name from the group of mappings in the web.xml?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap