Java Reference
In-Depth Information
Table 18.1 BudgetPro servlet actions
func parameter
Other params
Action
Next screen
name , dollars
Create a top-level account, save in
the session.
begin
main
none
none
mkacct
subacct
none
Get account from session.
cancel
main
name , dollars
Get account from session; create
subaccount.
create
main
Get account from session, look up
subaccount by name , save as current
in session.
cd
name
main
none
Get account from session, get
parent from account, save as current
in session.
back
main
The parsing of the parameters is very straightforward. The request param-
eter, part of the signature of the doGet() and doPost() methods, can be used
to retrieve the parameters we need:
String act = request.getParameter("func");
String name = request.getParameter("name");
String dollars = request.getParameter("dollars");
Notice that we always ask for all three parameters, even though we will
often use only one ( act ). Once we have the requested function in act , it's just
a matter of if-then-else-ing our way through the possible values and taking
the appropriate actions. We store, or retrieve, the current account in the
session manager, thereby providing continuity between browser requests
(Example 18.2).
The output is the page to send back to the browser. We create
that page as an object, either an AccountView or a SubPage . The
HttpServletResponse provides us with an output channel on which to write.
java.io.PrintWriter out = response.getWriter();
if (nextPage != null) {
response.setContentType("text/html");
out.println(nextPage.toString());
}
Search WWH ::




Custom Search