Pr.Pg Next Pg

JSP tutorials Implicit Objects

  • Implicit object are Java objects that implement interfaces in the Servlet and JSP API. This objects are created by the web container.

  • Since these objects are created automatically by the container and are accessed using standard variables, hence they are called implicit objects.

  • The implicit object are passed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration.

  • Implicit objects are useful while scripting JSP pages.

  • There are nine implicit objects available in JSP below chart shows the implicit object and its class.

 

 

Implicit Object

Class

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

 

Application

  • The scope of application implicit object is throughout the application. This objects are available at the widest context level, that allows to share information between the JSP pageís, servlet, and any web components within the same application.

 

Config

  • This is the ServletConfig object for this page. This stores servlet configuration data.

  • Config object allows to pass the initialization data to a JSP pageís servlet. Parameters of this objects can be set in the deployment descriptor(web.xml) inside the element <jsp-file>.

  • The method getInitParameter() is used to access the initialization parameters.

 

Out

  • 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.

  • This object allows us to access the servletís output stream and has a page scope.

  • It provides the output stream that enable access to the servlet's output stream.

 

Page

  • This object has a page scope and is an instance of the JSP page's servlet class that processes the current request.

  • Page object represents the current page that is used to call the methods defined by the translated servlet class.

  • First type cast the servlet before accessing any method of the servlet through the page.

 

Pagecontext

  • 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.

 

Exception

  • This implicit object exists only in a defined error page. It holds a reference to the uncaught exception that caused the error page to be called.

 

Request

  • Request object has a request scope that is used to access the HTTP request data, and also provides a context to associate the request-specific data.

  • Request object implements javax.servlet.ServletRequest interface.

  • It uses the getParameter() method to access the request parameter. The container passes this object to the _jspService() method.

 

Response

  • This object has a page scope that allows direct access to the HTTPServletResponse class object.

  • Response object is an instance of the classes that implements the javax.servlet.ServletResponse class.

  • Container generates to this object and passes to the _jspService() method as a parameter.

 

Session

  • 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.

Pr.Pg border                                              Next Pg