JSP config

JSP config object is used to send the configuration information to JSP page. Here, config is an instance of servlet's ServletConfig interface.

In this case, the information is send to JSP page through web.xml file. Config object is used to fetch this information. It is used widely for the initialization of parameters.

Note: - The scope of JSP config object is up to a single JSP page only.

Example of JSP Config

  In this example, web.xml file contains the information. The config object in index.jsp file fetches that information.

index.jsp

<html>
<head>
<title>Tutorial and Example</title>
</head>
<body>
<%
String name=config.getServletName();
out.print("<h2 align=center>Welcome to "+name+"</h2>");
%>
</body>
</html>

web.xml

<web-app>
<servlet>
<servlet-name>Tutorial and Example</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet> 
<servlet-mapping>
<servlet-name>Tutorial and Example</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>
Output: