Java Reference
In-Depth Information
resource can act upon them. To redirect a request is to cause the browser to send
a new request to a different resource. In the case of a user who logs off of the
application, the current session is explicitly invalidated so session data no longer
can be used. Also, the browser is directed to request the log on page to replace
the page currently displayed by the browser. This requires subsequent users to
log on and be validated. When the user clicks the Log out button, a parameter is
sent with a value of the text of the button.
Figure 12-24 displays lines 104 through 109 of the WebStocks servlet code.
Line 104 uses the getParameter() method of the request object to obtain the
form field parameter value associated with the name, logout. Parameter values
are returned as strings. If the result is not null, meaning that a parameter value
associated with the name, logout, was sent, then line 105 verifies the value of
the parameter. If the user has chosen to log out, line 107 calls the invalidate()
method for the session to invalidate the current session. Line 108 then calls the
response sendRedirect() method , which causes the server to convert the sup-
plied URL from a relative to an absolute URL, if necessary, and then send it to
the browser. The browser then sends a request for the new URL, just as when the
user initially logged on to the application. When redirecting a request to another
resource, the current request and response objects are discarded.
FIGURE 12-24
The following step enters the code to redirect an HTTP request.
To Redirect an HTTP Request
1. Enter lines 104 through 109 as shown in Figure 12-24.
TextPad displays the code to invalidate the session object and redirect the
request to the log on Web page (Figure 12-25).
getParameter() method
invalidate() method
sendRedirect() method
FIGURE 12-25
 
Search WWH ::




Custom Search