Java Reference
In-Depth Information
Table 9.1
The implicit JSP objects
Variable
Type
Purpose
request
HttpServletRequest
Http request originally sent to server
response
HttpServletResponse
Http response to request
session
HttpSession
Session object associated with the
above request and response
application
ServletContext
Holds references to other objects that
more than one user may access,
such as a database link
out
JspWriter
Object that writes to the response
output stream
exception
Throwable
Contains information about a runtime
error and is available only on
error pages
pageContext
PageContext
Encapsulates the page context
confi g
ServletConfi g
ServletConfi g object for this JSP
page
Object
The this object reference in this JSP
ServletContext is an interface implemented by each servlet engine that provides
a servlet with methods that allow it to fi nd out about its environment (independent
of any individual session). This interface has two methods that mirror the Session
class's methods getAttribute and setAttribute . The two methods have names, argu-
ments and return types that are identical to those of the corresponding Session meth-
ods. The signatures for these methods are repeated below.
￿ public Object getAttribute(String <name>)
￿ public void setAttribute(String <name>,
Object <attribute>)
As shown in Table 9.1 , the implicit object application is the ServletContext
object that is created automatically for a JSP and allows the programmer to retrieve
and set environment-level properties via the two methods above.
In the examples below, note the need for typecasting with getAttribute , since it
returns an Object reference.
Examples
String userName =
(String)application.getAttribute("name");
Float balanceObject =
(Float)application.getAttribute("balance");
setAttribute("total", new Integer(0));
Other methods of object application that are sometimes useful are listed below
and have purposes that are self-evident.
 
Search WWH ::




Custom Search