Skip to content
Related Articles

Related Articles

Improve Article

JSP Config – Implicit Objects

  • Last Updated : 28 Jul, 2021
Geek Week

JSP Config is an implicit object which is used to transmit the configuration details to the JSP page. In JSP, Config is an instance of type ServletConfig. This implicit object is used to acquire an initialization parameter for a certain JSP page. For each JSP page, the config object is generated through the web container. JSP’s config object carries the configuration pieces of information like the username, password, driver name, servlet name, servlet context, specification names, and their values settle in the web.xml (configuration file). 

It is an object of type javax. servlet.ServletConfig interface.

Through web.xml file the detail is send to JSP file. To fetch this detail the Config object is used. Normally, it is used extensively for the initialization parameters like as the paths or file locations from the web.xml file.

Note: JSP Config object has scope only up to a single JSP page.

Methods of ServletConfig interface are listed alongside the action performed from the below table as follows:



ServletContext getServletContext()          From the session, this method withdraws an object with a name.
String getInitParameter(String name)This method receives an object saved in session with a name, or null.
Enumeration getInitParameterNames()In a session, this method places an object with a name.
String getServletName()This method gives back a RequestDispatcher that behaves as a cover for the resource at the path.


We will be proposing examples directly and later on will append the visual aid representing JSP pages as an output. So example of JSP Config implicit object is as follows:

  • In this example, the various variables and their values are contained in the ‘web.xml file‘. 
  • The config object is in ‘index.jsp‘ file retrieves that information and displays it to the user. 

Example 1: index.html File 


<!DOCTYPE html>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<form action="welcome">
<input type="text" name="uname">
<input type="submit" value="go"><br/>

Example 2: web.xml File


<?xml version="1.0" encoding="UTF-8"?>
         id="WebApp_ID" version="4.0">

Example 3: ‘welcome.jsp’ FIle 


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html>
<meta charset="ISO-8859-1">
out.print("Welcome "+request.getParameter("uname"));
String driver=config.getInitParameter("dname");
out.print("<br/>driver name is="+driver);  


These are the screenshots of the outputs of the above JSP page.

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :