Introduction of application implicit Object-: The application object is an instance of a javax.servlet.ServletContext object. The application object is created by the container when the application is deployed on the web server.The application object is used to set, get or remove the attribute.
Methods of application Implicit Object in jsp -: There are several method these are using
getAttribute () -: This is used to get the attribute set on the application object. The name of the attribute set on this method is passed. If the given attribute name is false then ‘null’ returns. for example
<% application.setAttribute("attr", "welcome netnic"); application.getAttribute("attr"); %>
setAttribute () -: This is used to set the attribute on the application. The attribute name and its value are assigned to the attribute. for example
<% application.setAttribute("attr", "welcome netnic"); %>
removeAttribute ()-: This method These are used to remove the set attribute with the given attribute name.for example
<%@page import="java.util.*" %> <% application.setAttribute("attr1", "welcome"); application.setAttribute("attr2", "netnic"); application.removeAttribute("attr2"); Enumeration e=application.getAttributeNames(); while(e.hasMoreElements()){ Object obj=e.nextElement(); String name=(String)obj; out.println("Attribute Name : " + name + ""); } %>
The getAttributeNames () -this method returns the names of all the attributes of the application object in enumeration.for example
Enumeration e=application.getAttributeNames(); while(e.hasMoreElements()){ Object obj=e.nextElement(); String name=(String)obj; out.println("Attribute Name : " + name + " "); } %>
getInitParameter ()-: This method is used to obtain its value through the name of the initialization parameter given on web.xml. for example
<%@page import="java.util.*" %> <% out.print("Parameter Value : " + config.getInitParameter("MyWeb")); %>
getInitParameterNames ()– This method returns the names of the initialization parameter given in web.xml in enumeration. for example
<%@page import="java.util.*" %> <% out.print("Parameter Value : " + config.getInitParameter("MyWeb")); %> <%@page import="java.util.*" %> <% Enumeration e=config.getInitParameterNames(); while(e.hasMoreElements()){ Object obj=e.nextElement(); String param=(String)obj; out.println("Intialization Parameter Name : "+ param + ""); } %>
getRealPath ()-: This method returns the full path of the system. The given value is given at the end of the returned path.for example
<% out.println(application.getRealPath("Sample")); out.println(application.getRealPath("/")); %>
log (string message) –This method is used to write text messages on the default log file of JSP Web container or JSP Engine. for example
<% application.log("my log"); %>
getServerInfo ()-This method; Returns the name and version of the JSP Engine or JSP Web Container. for example
<% out.print(application.getServerInfo()); %>
getMajorVersion ()– This method returns the major version of the Servlet API being used for the application object. for example
<% out.print(application.getMajorVersion()); %>
getMinorVersion () -:This method returns the minor version of the Servlet API being used for the application object. for example
<% out.print(application.getMinorVersion()); %>