Master java skills

application Implicit Object

application implicit object is ServletContext type. Just like in Servlet, there is one ServletContext object per application, here in jsp also, there is one application implicit object.

Application implicit object can be used to get initialization parameters from web.xml. It can also be used to get/ set /remove attributes from the application scope.

These initialization parameters can be used by all jsp pages.

Example of application implicit object

index.html

<html>
  <form action="welcome">  
    Username : <input type="text" name="username">  
    <input type="submit" value="Submit"><br/>  
  </form>
<html>  

welcome.jsp

<html>
  <body>
    <%   
      out.print("Welcome " + request.getParameter("username"));  
      String initParam = application.getInitParameter("pName");  
      out.print("<br>Initial parameter pName value is = " + initParam);  
    %>
  </body>
<html>

web.xml

<web-app>

	<servlet>
		<servlet-name>exampleServlet</servlet-name>
		<jsp-file>/welcome.jsp</jsp-file>
	</servlet>

	<servlet-mapping>
		<servlet-name>exampleServlet</servlet-name>
		<url-pattern>/welcome</url-pattern>
	</servlet-mapping>

	<context-param>
		<param-name>pName</param-name>
		<param-value>pValue</param-value>
	</context-param>

</web-app>

Test