Implicit Objects in JSP, Config Implicit Object in JSP, How to get Configuration Information from a JSP page


Implicit Objects in JSP, Config Implicit Object in JSP,  How to get Configuration Information from a JSP page

config is an object of ServletConfig class in Java Servlet, It is used to get the configuration information from an xml configuration file to a JSP page. for example if we have an XML configuration file in our application and we have define the database connection string into the <init-param> tag and then we want to access the value of the variables which are define into the <init-param> then we are used the config.getInitParameter(String param) method of the config object.It is used to get info for a single jsp page.

Example:-

web.xml

<web-app>
<servlet>
<servlet-name>talibhassan</servlet-name>
<jsp-file>/hello.jsp</jsp-file>
<init-param>
<param-name>user</param-name>
<param-value>Talib Hassan</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>talibhassan</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>

hello.jsp

<html>
<head>
<title>Hello User</title>
</head>
<body>
<%
String user=config.getInitParameter("user");
%>
<h1>Welcome <%=user%></h1>
</body>
</html>
</html>

The above example print the Welcome Talib Hassan

{ 0 comments... read them below or add one }

Post a Comment