Java Reference
In-Depth Information
Forwarding an HTTP Request
For valid user actions other than logging out, the servlet must determine the
appropriate resource needed and then send the current request to the appropri-
ate resource. With the exception of logging out, which redirects the HTTP
request, each user selection on a Web page requiring action by the servlet — for
example, adding a stock, deleting a stock, changing a password — passes a hid-
den parameter to the servlet. This parameter, WSaction, determines which action
the servlet takes to respond to the request. Depending on the action requested,
the servlet may complete one or more tasks, including getting another parameter
value, calling a method, removing an attribute, or setting an attribute to indicate
the name of the next resource to use. Because the called methods throw excep-
tions, the calls are within a try block.
Figure 12-26 displays lines 110 through 199 of the WebStocks servlet code.
For example, lines 119, 123, 127, and 131 each call a single method. The called
method will set the attribute for the next resource, as appropriate. The code on
lines 135 through 138 gets a parameter value, passes that value to a method call,
sets an attribute representing the result of the call, and then sets the attribute for
the next resource to use.
(continued)
FIGURE 12-26
 
Search WWH ::




Custom Search