A JSP program can have two types of objects.
• Explicit objects
• Implicit objects
1. Explicit Objects
Explicit objects are those which are created by the programmer manually.
Ex:<% java.util.Date d=new java.util.Date ();%>
In JSP, implicit objects are important because they contain high degree of functionality. They are used in a JSP page to make it dynamic. The JSP container automatically initiates these objects while writing the script content in the scriptlet and expression tags. So these objects are called implicit objects. These are predefined and accessible to all JSP pages. Sun Microsystems has given JSP specification with some object reference names so that vendor or server developer must have to initialize these objects in the _jspService () method.
Features of Implicit Objects
• Programmer need not declare explicitly these implicit objects.
• Available to all JSP pages, so no need to import them into JSP page.
• Allow developers to access the services and resources provided by the web container.
Types of Implicit Objects
During page compilation the JSP engine initiates nine implicit objects in the _jspService () method. These JSP implicit objects are:
• Request object: It is of type javax.servlet.HttpServletRequestinterface. Its use is similar Servlet. When client makes a request then request objects are passed to _jspService (-,-) as parameters. Its visibility scope is specific to each request.
• Response object: After _jspService (-,- )is executed, response object carries response to browser window. The response object is of type javax.servlet. http.HttpServletResponsewterface. Its visibility scope is specific to each response.
• Out object: The out implicit object provides access to the Servlet’s output stream. This object is a subtype of javax.servlet.jsp.JspWriter (Abstract Class). The out object is used to write the text data. Its visibility scope is specific to each JSP page.
• Page object: It is of type java.lang.Object. it is rarely used in a document because variable type is object. It cannot be used directly to call the servlet methods. Its visibility scope is specific to each JSP page.
• Page Context object: It represents the context of the current JSP page. This object isjavax.servlet.jsp.PageContextinterface type and its visibility scope is specific to each JSP page.
• Application object: It is of javax.servlet.ServletContextinterface type. Its visibility scope is global in the web application.
• Session object: It is of javax.servlet.http.HttpSessioninterface type. Visibilty scope is specific to each browser window. It is declared if the value of the session attribute in a page directive is true.
• Config object: This config object specifies the configuration of the parameters passed to a JSP page. It is of javax.servlet. ServletConfiginterface type. To demonstrate this we need to associate a Servlet file by using <jsp-file> element.
• Exception object: It is of java .lang. Throwable (class) type. Visible only in JSP error pages that have the ErrorPage attribute set to ‘true’ with page directives.
All implicit objects are available within scriptlet and expression tags only but not available within declaration tag. All implicit objects are the objects of underlying Servlet Container supplied by Java classes but we never bother about these classes because these classes’ name will change based on the container/server that we used.
Example: In Tomcat server, request object class name is org.
apache.catnlina.connector.ReqestFacade.
Working with implicit objects
Here, we have given one type of example; later you can find other types of examples.
Deployment directory structure
Request url: https://ecomputernotes.com:8081/Implijsp/first.html
First.html
<html> <body> <form action=“first.jsp”> name: <input type=“text” name= “t1”> <input type= “submit” value= “enter”/> </form> </html>
first.jsp
<html> <b> Implicit objects utilization </b> <hr> <body> Mr/Ms: <b> <font size=“5” color=“green”> <%=request.getParameter (“t1”)) %> </font> welcome to interface software: </b> <br> <br> <table border=“l” color=“blue”> <tr> <td> request object class name is </td> <td> <i> <%=request.getClass () %> </i> </td> </tr> <tr> <td> response object class name is </td> <td> <i> <%=response.getClass () %> </i> </td> </tr> <tr> <td> session object class name is </td> <td> <i> <%=session.getClass () %> </i> </td> </tr> <tr> <td> application object class name is </td> <td> <i> <%=application.getClass ( ) %> </i> </td> </tr> <tr> <td> pageContext object class name is </td> <td> <i> <%=pageContext.getClass () %> </i> </td> </tr> <tr> <td> page object class name is </td> <td> <i> <%=page.getClass () %> </i> </td> </tr> <tr> <td> exception object is not visible inside normal page it visible inside only in error page </td> <td> <%--<%=exception.getClass () %>--%> </td> </tr> <tr> <td> config object class name is </td> <td> <i> <%=config.getClass () %> </i> </td> </tr> <tr> <td> out object class name is </td> <td> <i> <%=out.getClass () %> </i> </td> </tr> <tr><td> <b> other method call on request object </b> </td> </tr> <tr> <td> request header </td> <td> <%=request.getHeader (“user-agent”) %> </td> </tr> <tr> <td> request method </td> <td> <%=request.getMethod () %> </td> </tr> <tr> <td> request URL </td> <td> <%=request.getRequestURL () %> </td> </tr> <tr> <td> request protocol </td> <td> <%=request.getProtocol () %> </td> </tr> </table></html>