JSP Implicit Objects
JSP Implicit Objects
JSP Implicit Objects
JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in
each page and developer can call them directly without being explicitly declared. JSP Implicit
Objects are also called pre-defined variables.
Object Description
out This is the PrintWriter object used to send output to the client.
page This is simply a synonym for this, and is used to call the methods
defined by the translated servlet class.
The request object provides methods to get HTTP header information including form data, cookies,
HTTP methods etc.
We would see complete set of methods associated with request object in coming chapter: JSP -
Client Request.
The response object also defines the interfaces that deal with creating new HTTP headers.
Through this object the JSP programmer can add new cookies or date stamps, HTTP status codes
etc.
We would see complete set of methods associated with response object in coming chapter: JSP -
Server Response.
The JspWriter object contains most of the same methods as the java.io.PrintWriter class. However,
JspWriter has some additional methods designed 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.
Method Description
out.printlndataTypedt Print a data type value then terminate the line with new
line character.
The session object is used to track client session between client requests. We would see complete
usage of session object in coming chapter: JSP - Session Tracking.
This object is a representation of the JSP page through its entire lifecycle. This object is created
when the JSP page is initialized and will be removed when the JSP page 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
This object allows the JSP programmer access to the Servlet or JSP engine initialization parameters
such as the paths or file locations etc.
The following config method is the only one you might ever use, and its usage is trivial:
config.getServletName();
This returns the servlet name, which is the string contained in the <servlet-name> element
defined in the WEB-INF\web.xml file
This object is intended as a means to access information about the page while avoiding most of
the implementation details.
This object stores references to the request and response objects for each request. The
application, config, session, and out objects are derived by accessing attributes of this object.
The pageContext object also contains information about the directives issued to the JSP page,
including the buffering information, the errorPageURL, and page scope.
One of the important methods is removeAttribute, which accepts either one or two arguments.
For example, pageContext.removeAttribute " attrName " removes the attribute from all scopes,
while the following code only removes it from the page scope:
pageContext.removeAttribute("attrName", PAGE_SCOPE);
You can check a very good usage of pageContext in coming chapter: JSP - File Uploading.
The page object is really a direct synonym for the this object.
We would see complete usage of this object in coming chapter: JSP - Exception Handling.
Processing math: 100%