JSP Implicit Objects
Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.
JSP Implicit Objects
Rating:
Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects. The implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration.
The implicit objects available in JSP are as follows:
| application | javax.servlet.ServletContext |
| config | javax.servlet.ServletConfig |
| exception | java.lang.Throwable |
| out | javax.servlet.jsp.JspWriter |
| page | java.lang.Object |
| PageContext | javax.servlet.jsp.PageContext |
| request | javax.servlet.ServletRequest |
| response | javax.servlet.ServletResponse |
| session | javax.servlet.http.HttpSession |
The application object has an application scope. It is an instance of the javax.servlet.ServletContext class. It represents the context within which the JSP is executing. It defines a set of methods that a servlet uses to communicate with its servlet container. These functions include getting the MIME type, request dispatching, and writing contents to a log file. It allows the Web components in the JSP page in the application to share information.
The config object has a page scope. It is an instance of the javax.servlet.ServletConfig class. The ServletConfig parameter can be set up in the web.xml inside the <jsp-file> element. It uses the getInitParameter(String param) to obtain initialization parameters and the getServletContext() method to obtain the ServletContext object.
The exception object has a page scope. It is an instance of the java.lang.Throwable class. It refers to the runtime exception that resulted in the error-page being invoked. This is available only in an error page, i.e., a page that has isErrorPage=true in the page directive.
The out object has a page scope. It is an instance of the javax.servlet.jsp.JspWriter class. The JspWriter class is the buffered version of the Printwriter class. It represents the output stream opened back to the client and provides the access to handle servlet's output stream.
The page object has a page scope. It is an instance of the java.lang.Object class. It represents the JSP page and is used to call the methods defined by the translated servlet class. To access any of the methods of the servlet through the page, it must be first cast to type Servlet.
The PageContext object has a page scope. It is an instance of the javax.servlet.jsp.PageContext class. It encapsulates the page-context for the particular JSP page. A PageContext instance provides access to all the namespaces associated with a JSP page. It also provides access to several page attributes such as to include some static or dynamic resource. Implicit objects are added to the PageContext automatically.
The request object has a request scope. It is an instance of the classes that implement the javax.servlet.ServletRequest interface. It encapsulates the request coming from a client and uses the getParameter() method to access request parameters. It is passed to the JSP by the container as a parameter to the _jspService() method.
The response object has a page scope. It is an instance of the classes that implement the javax.servlet.ServletResponse class. It encapsulates the response generated by the JSP to be sent to the client in response to the request. It is generated by the container and passed to the JSP as a parameter to the _jspService() method.
The session object has a scope of an entire HttpSession. It is an instance of the javax.servlet.http.HttpSession class. It represents the session created for the requesting client, and stores objects between client's requests. The session object views and manipulates session information, such as the session identifier, creation time, and last accessed time. It also binds objects to a session, so that the user information may persist across multiple user connections. The session object is valid only for HTTP requests.
Rating:
Was this information helpful?
Other articles
- What is the <load-on-startup> element?
- What is the getRemoteHost() method?
- What is the findAttribute() method?
- What is the <jsp:doBody> standard action?
- What is the getDateHeader() method?
