JSP implicit object "config"

The config object is an instance of a servlet API javax.servlet.ServletConfig interface. It gives facility for a JSP page to obtain the initialization parameters available.
Example of implict object "config" :
index.html
<html> <head> <title>welcome implict object config example</title> </head> <body> <form action="welcome" method="post"> User Name <input type="text" name="user"> &nbsp; <input type="submit" value="Submit"> <br> </form> </body> </html>
index.jsp
<%@ page language="java" %> <html> <head> <title>welcome page</title> </head> <body> <% String name=request.getParameter("user"); out.println("hi "+name ); out.println("<BR>"); String website=config.getInitParameter("website"); out.println("welcome to "+website); %> </body> </html>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>ConfigExample</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>welcome</servlet-name> <jsp-file>/index.jsp</jsp-file> <init-param> <param-name>website</param-name> <param-value>www.nsstudent.com</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>welcome</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping> </web-app>
Output
config
config
Download this example
 



 

Latest Tutorial


Most Visited Tutorial