8jsp Implicit Objects
8jsp Implicit Objects
http://www.tuto rialspo int.co m/jsp/jsp_implicit_o bje cts.htm Co pyrig ht © tuto rials po int.co m
JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each pag e and
developer can call them directly without being explicitly declared. JSP Implicit Objects are also called pre-
defined variables.
out T his is the PrintWriter object used to send output to the client.
pag eContext T his encapsulates use of server-specific features like hig her performance
J spWriters.
pag e T his is simply a synonym for this, and is used to call the methods defined by
the translated servlet class.
T he request object provides methods to g et HT T P header information including form data, cookies, HT T P
methods etc.
We would see complete set of methods associated with request object in coming chapter: JSP - Client Request.
T he response object also defines the interfaces that deal with creating new HT T P headers. T hroug h this object
the JSP prog rammer can add new cookies or date stamps, HT T P status codes etc.
We would see complete set of methods associated with response object in coming chapter: JSP - Server
Response.
T he initial JspWriter object is instantiated differently depending on whether the pag e is buffered or not.
Buffering can be easily turned off by using the buffered='false' attribute of the pag e directive.
T he JspWriter object contains most of the same methods as the java.io.PrintWriter class. However, JspWriter
has some additional methods desig ned to deal with buffering . Unlike the PrintWriter object, JspWriter throws
IOExceptions.
Following are the important methods which we would use to write boolean char, int, double, object, String etc.
out.println(dataT ype dt) Print a data type value then terminate the line with new line
character.
T he session object is used to track client session between client requests. We would see complete usag e of
session object in coming chapter: JSP - Session T racking .
T his object is a representation of the JSP pag e throug h its entire lifecycle. T his object is created when the JSP
pag e is initialized and will be removed when the JSP pag e is removed by the jspDestroy() method.
By adding an attribute to application, you can ensure that all JSP files that make up your web application have
access to it.
You can check a simple use of Application Object in chapter: JSP - Hits Counter
T his object allows the JSP prog rammer access to the Servlet or JSP eng ine initialization parameters such as the
paths or file locations etc.
T he following config method is the only one you mig ht ever use, and its usag e is trivial:
config.getServletName();
T his returns the servlet name, which is the string contained in the <servlet-name> element defined in the WEB-
INF\web.xml file
T his object is intended as a means to access information about the pag e while avoiding most of the
implementation details.
T his object stores references to the request and response objects for each request. T he application, config ,
session, and out objects are derived by accessing attributes of this object.
T he pag eContext object also contains information about the directives issued to the JSP pag e, including the
buffering information, the errorPag eURL, and pag e scope.
T he Pag eContext class defines several fields, including PAGE_SCOPE, REQUEST _SCOPE,
SESSION_SCOPE, and APPLICAT ION_SCOPE, which identify the four scopes. It also supports more than 40
methods, about half of which are inherited from the javax.servlet.jsp. JspContext class.
One of the important methods is removeAttribute, which accepts either one or two arg uments. For example,
pag eContext.removeAttribute ("attrName") removes the attribute from all scopes, while the following code only
removes it from the pag e scope:
pageContext.removeAttribute("attrName", PAGE_SCOPE);
You can check a very g ood usag e of pag eContext in coming chapter: JSP - File Uploading .
We would see complete usag e of this object in coming chapter: JSP - Exception Handling .