9 JSP Implicit objects and Scope


One of the advantages of JSP over Servlets is Implicit Objects. Implicit objects make JSP coding simple. In Servlets, the Programmer should create these objects and then use, example, objects of HttpSession, ServletConfig, PrintWriter etc. But in case of JSP, just use them as they are implicitly created and supplied by JSP container. Programmer can use them straightaway in the code. As they are created by JSP container implicitly, they are known as implicit objects.

JSP Implicit objects are always either an instance of a class or interface belonging to a specific API.

There are total 9 JSP implicit objects . Following is the list of JSP Implicit objects.

Object Class or Interface Description Scope
page javax.servlet.jsp.HttpJspPage Represents this object for the instance of the page Page
config javax.servlet.ServletConfig Represents ServletConfig for the JSP page Page
out javax.servlet.jsp.JspWriter Represents the JspWriter object to the output stream Page
pageContext javax.servlet.jsp.PageContext Represents the page context for the JSP Page
application javax.servlet.ServletContext Represents the servlet context returned from a call to getServletConfig.getContext Application
session javax.servlet.http.HttpSession Represents session object, if any, during the HTTP request Session
exception java.lang.Throwable Represents the uncaught error Page
response javax.servlet.http.HttpServletResponse Reprsents the response object that triggered the response Response
request javax.servlet.http.HttpServletRequest Represents the request objects that triggered the request Request

The above objects are used in all the examples of JSP.

1. request implicit object

This is an implicit object of javax.servlet.http.HttpServletRequest interface.
This object is used by Programmer to extract (from JSP) the data send by client like user name and password and also header information, request query parameters, retrieving cookies from client etc. A program is available at Using implicit object request JSP Example

2. response implicit object

This is an implicit object of javax.servlet.http.HttpServletResponse interface. This is used to send response to client (via out object). Used for setting content type, sending cookies to client, redirect operations etc. A program is available at Using implicit object response JSP Example

3. out implicit object

It is an implicit object of javax.servlet.jsp.JspWriter, as subclass of java.io.Writer. Programmer uses out object to send response to client. This is mostly used Programmer. A program is available at Using implicit object out in JSP Example.

4. session implicit object

It is an implicit object of javax.servlet.http.HttpSession interface. It represents the communication with the client. The session object is used to store a single client’s state. A program is available at Using implicit object session JSP Example.

5. application implicit object

It is an implicit object of javax.servlet.ServletContext interface. This represents the global object wherein all the JSPs of an application can store and retrieve values. Using this object, all JSPs can communicate in between. A program is available at Using implicit object application in JSP with Example.

6. exception implicit object

It is an instance of class java.lang.Throwable. Used to generate error pages. A program is available at Using implicit object exception JSP Example.

7. config implicit object

This config represents an object of javax.servlet.ServletConfig interface. Used to retrieve configuration or initialization particulars of a jSP. A program is available at Using JSP implicit object config Example.

8. page implicit object

It is an instance of class java.lang.Object. This object represents the current JSP page. This objects takes lot of memory and thereby used rarely. It represents or used as a reference to the generated Servlet.

9. pageContext implicit object

It is an instance of javax.servlet.jsp.PageContext abstract class. It gets the all the page context information. Used to forward request to other sources with get and set methods. It can used as a reference to all other implicit objects.

Note: The importance of the four implicit objects of request, session, application and pageContext is that they can transfer information between JSP pages and Servlets as an easy data-sharing mechanism.

    Examples on Implicit Objects

  1. Using JSP implicit object config Example
  2. Using implicit object application in JSP with Example
  3. Using implicit object out in JSP Example
  4. Using implicit object session JSP Example
  5. Using implicit object request JSP Example
  6. Using implicit object response JSP Example
  7. JSP sendRedirect Example
  8. Using implicit object exception JSP Example

JSP View All

1 thought on “9 JSP Implicit objects and Scope”

Leave a Comment

Your email address will not be published.