JSP - SPLessons

JSP Config Object

Chapter 16

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JSP Config Object

JSP Config Object

shape Description

The JSP Config Object is created by the JSP container while translating the JSP page to Servlet source to help JSP programmers. This JSP config object is used to get an information from the web.xml for the particular JSP page. The JSP Config Object has some methods which are used in Servlet. They are
Following is the difference between Config and Application.

  • Config is for a specific Servlet/JSP, the config parameter are unknown to other Servlet/JSP and it has Session Scope.
  • application( ServletContext ) parameter are specified for the entire application. These variables are access across the application.

shape Example

Following is an example.


<h2><a href="./welcome">click here</a></h2>

Here just created the button Click here, the URL name should be match with web.xml file URL.



Here make sure that servlet name should be same that is Config, URL should be match with HTML form, parametes are passing from the web.xml file by using the tag .

<% String userName = config.getInitParameter("user_name"); 
out.println("your name get from web.xml:"+userName); %>

Here name will be retrieved from the web.xml page that is SPlessons and that will be printed using out.println.


Output will be as follows, where click on the click here button that was created in main page jspconfig.html .

After clicking on the button output will be as follows with the name that was mentioned in the web.xml .


shape Key Points

  • It is an implicit object, utilized for getting setup data for a specific JSP page.
  • JSP Config Object is an object of javax.servlet.ServletConfig.
  • web.xml is used to access the init parameters of the servlet.