In this tutorial you will learn about the JSP Config Implicit Object and its application with practical example.
JSP Config Implicit Object
The config implicit object is an instance of javax.servlet.ServletConfig. Config implicit object is used for getting configuration information of particular jsp page. This implicit object created by web container .
Example: Let’s get understand it by simple example. We need to initialize our params in web.xml file, check one by one.
#web.xml: Here we will declare <init-param> in the <servlet> tag, like below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>Mine</servlet-name> <jsp-file>/Welcome.jsp</jsp-file> <init-param> <param-name>SiteName</param-name> <param-value>w3adda.com</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Mine</servlet-name> <url-pattern>/Welcome</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app> |
#Welcome.jsp: Here we will get our configuration file from web.xml, check below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <% String siteName = config.getInitParameter("SiteName"); out.print("Welcome " + siteName); %> </body> </html> |
Output: The output of above code will look like below image.