Implicit Objects in JSP - JEE
Home » JEE, Jsp, Tech Notes

Implicit Objects in JSP

16 April 2009 No Comment

Implicit object are those objects which are available in jsp by default. Developer does not need to declare these objects, the web container creates them. What would be rational behind creation of such objects? Why would thecontainer create these objects? Can we not work without these objects? We will try to find answers to these questions in this article.

Web container executes the JSP page as a servlet. Servlet operates in request – response model. All objects, that are associated with any servlet by default, are part of this implicit object group. Each servlet has information related to the container’s environment, the servlet itself, the interaction session with user, definitely the request and response, etc. This information along with information related to the jsp page itself, is made available to the jsp via the implicit objects. The following is a list of jsp implicit objects:

  • request
  • response
  • pageContext
  • session
  • application
  • out
  • config
  • page
  • exception

Let us look at these objects in detail.

request:

  • Request object represents the request made by a client to the servlet.
  • This request is passed as an instance of javax.servlet.HttpServletRequest object.
  • This is an input parameter to the jspService() method.
  • Contains http header, request attributes, session etc.

response:

  • It represents the response generated by the servlet.
  • This is an instance of javax.servlet.HttpServletResponse class.
  • This is another input parameter to the jspService() method of the generated servlet.

pageContext:

  • Using this object, we can interact with the servlet container.
  • It is an instance of javax.servlet.jsp.PageContext class.
  • Container can manage page attributes like error pages, forwarding pages and including pages using this object.

session:

  • Represents the session between client and servlet (server).
  • Instance of HttpSession class.
  • Can be used to store attributes applicable to user session and not request.

application:

  • It is an instance of ServletContext class.
  • Used to share data amongst servlets, jsps and html pages in an application.

out:

  • This object is used to send output to the client.
  • It is an instance of javax.servlet.jsp.JspWriter class.
  • Based on the content type defined, the output will be generated.
  • Some of the methods available are print, println, flush, etc.

config:

  • This represents the servlet configuration.
  • It is an instance of javax.servlet.ServletConfig class.

page:

  • Represents the instance of generated servlet – “this”.

exception:

  • It is an instance of java.lang.Throwable class.
  • It encapsulates the exception thrown by the servlet.
  • If the jsp contains page directive for error page, then this exception is forwarded to that page.

To summarize, implicit objects are available in the jsp by default, and these objects can be used to serve a definite purpose which would otherwise be difficult.

<<Previous   Home   Next>>

 

More Related Posts in JEE, Jsp, Tech Notes

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.