Config Implicit Object in JSP with examples:
It is an instance of javax.servlet.ServletConfig. 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:
String getInitParameter(String paramname) – Same what we discussed in
application implicit object tutorial.
Enumeration getInitParameterNames() – Returns enumeration of
Initialization parameters.
ServletContext getServletContext() – This method returns a reference to
the Servlet context.
String getServletName() – It returns the name of the servlet which we
define in the web.xml file inside <servlet-name> tag.
Config Implicit Object Example:
web.xml:
Let’s say below is my web.xml file. I’m just defining servlet name and servlet
mapping in it. Later, I would fetch few details from this file using config
implicit object.
<web-app>
<servlet>
<servlet-name>ycdServlet</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>ycdServlet</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>