Java Reference
In-Depth Information
Figure 21.4 shows the output of time.jsp .
FIGURE 21.4
Using an expres-
sion in a JSP
page.
When a page includes an expression, it's evaluated to produce a value and displayed on
the page. If the expression produces different values each time the page is displayed, as
time.jsp does in line 7 of Listing 21.4, this is reflected in the page when loaded in a
web browser.
There are several servlet objects you can refer to in expressions and other elements of a
JSP page using the following variable names:
out —The servlet output stream
n
request —The HTTP servlet request
n
response —The HTTP servlet responses
n
session —The current HTTP session
n
application —The servlet context used to communicate with the web server
n
config —The servlet configuration object used to see how the servlet was initial-
ized
n
Using these variables, you can call the same methods from within a page that are avail-
able in a servlet.
Listing 21.5 contains the text of the next page you'll create, environment.jsp ,
which shows how the request variable can be used on a page. This variable
represents an object of the HttpServletRequest class, and you can call the object's
getHeader( String ) method to retrieve HTTP headers that describe the request in more
detail.
21
LISTING 21.5
The Full Text of environment.jsp
1: <html>
2: <head>
3: <title>Environment Variables</title>
4: </head>
Search WWH ::




Custom Search