JSP implicit object "application"

The application object is an instance of a servlet API javax.servlet.ServletContext interface. It gives facility for a JSP page to obtain and set information about the web application in which it is running. It behaviour is same as servletContext and get information from context-param value.
Example of implict object "application" :
index.html
<html> <head> <title>welcome implict object application 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=application.getInitParameter("website"); out.println("welcome to "+website); %> </body> </html>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>applicationExample</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>website</param-name> <param-value>www.nsstudent.com</param-value> </context-param> <servlet> <servlet-name>welcome</servlet-name> <jsp-file>/index.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>welcome</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping> </web-app>
Output
application
application
Download this example
 



 

Latest Tutorial


Most Visited Tutorial