< Prev
Next >

JSP config object

JSP's config object holds the configuration details like the username, password, parameter names and their values set in the configuration file(web.xml) and it is an object of type javax.servlet.ServletConfig interface.

Methods of ServletConfig interface

Methods Description
String getInitParameter(String name) This method gets an object stored in a session with a name, or null.
Enumeration getInitParameterNames() This method sets an object with a name in a session.
ServletContext getServletContext() This method removes an object with a name from the session.
String getServletName() This method returns a RequestDispatcher which acts as a wrapper for the resource at the path.

An example of using the config object

In the upcoming example, we are first going to set the configuration data by setting a few variables and their values in the configuration file, web.xml as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

  <display-name>Welcome tomcat</display-name>
     Welcome tomcat






and next we are going to retrieve the values of these configured variables using the JSP inbuilt config object and display it to the user.

<title>Using JSP config object</title>


String sname = config.getServletName();
out.println("Servlet Name is "+ sname); 


out.println("Name variable retreived using config object : " + config.getInitParameter("Name")); 
out.println("Count variable retreived using config object : " + config.getInitParameter("Count"));


Executing the JspConfig.jsp gives us the following window displaying the values of initialized variables/parameters accessed using config JSP implicit object.


Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter

< Prev
Next >
< JSP application object
JSP exception object >

Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page