Config Implicit Object in JSP by R4R Team

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:

Lets say below is my web.xml file. Im 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>

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!