JSP Implicit Objects

JSP Container makes certain JAVA Objects available on JSP. These objects are called Implicit objects.  JSP Implicit objects are created by the web container. Implicit objects need not to be declared, defined or instantiated like other JAVA Objects. These implicit objects are Java objects that implement interfaces in the Servlet and JSP API. Scripting elements in a JSP page can make use of these JSP implicit objects. There are nine JSP implicit objects available.Developer can use these objects by directly calling it by name.

1 request implicit object :

This is the HttpServletRequest associated with the request, and lets you look at the request parameters (via getParameter), the request type (GET, POST, HEAD, etc.), and the incoming HTTP headers (cookies, Referer, etc.).

Strictly speaking, request is allowed to be a subclass of ServletRequest other than HttpServletRequest, if the protocol in the request is something other than HTTP.

2 response implicit object :

The JSP implicit response object is an instance of a java class that implements the javax.servlet.http.HttpServletResponse interface. It represents the response to be given to the client. The response implicit object is generally used to set the response content type, add cookie and redirect the response.Container generates to this object and passes to the _jspService() method as a parameter.

Note that, since the output stream (see out below) is buffered, it is legal to set HTTP status codes and response headers, even though this is not permitted in regular servlets once any output has been sent to the client.

3 out implicit object :

This is the PrintWriter used to send output to the client.

However, in order to make the response object (see the previous section) useful, this is a buffered version of PrintWriter called JspWriter.

Note that you can adjust the buffer size, or even turn buffering off, through use of the buffer attribute of the page directive.

Also note that out is used almost exclusively in scriptlets, since JSP expressions automatically get placed in the output stream, and thus rarely need to refer to out explicitly.

4 session implicit object :

This is the HttpSession object associated with the request.

Recall that sessions are created automatically, so this variable is bound even if there was no incoming session reference.

The one exception is if you use the session attribute of the page directive to turn sessions off, in which case attempts to reference the session variable cause errors at the time the JSP page is translated into a servlet.

5 application implicit object :

This is the ServletContext as obtained via getServletConfig().getContext(). It is used to share information among all users of a currently active application. The JSP implicit application object is an instance of a java class that implements the 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.

6 exception implicit object :

The JSP implicit exception object is an instance of the java.lang.Throwable class. It is available in JSP error pages only. It represents the occurred exception that caused the control to pass to the JSP error page.

7 config implicit object :

The JSP implicit config object is an instance of the java class that implements javax.servlet.ServletConfig interface. It gives facility for a JSP page to obtain the initialization parameters available.

8 page implicit object :

The JSP implicit page object is an instance of the java.lang.Object class. It represents the current JSP page. That is, it serves as a reference to the java servlet object that implements the JSP page on which it is accessed. It is not advisable to use this page implicit object often as it consumes large memory.

9 pageContext implicit object :

JSP introduced a new class called PageContext to encapsulate use of server-specific features like higher performance JspWriters.

The idea is that, if you access them through this class rather than directly, your code will still run on “regular” servlet/JSP engines.

 

<<Previous <<   || Index ||   >>Next >>
Previous
Next