Java Reference
In-Depth Information
of a Web site provided entirely via servlets, the shopping cart example from the
previous chapter will be re-implemented.
The initial page will be renamed ShoppingCart X .html . The only change required
for this page is the address for the form's ACTION attribute. Instead of specifying a
servlet called Selection , this will now specify a JSP called Selection.jsp :
<FORM METHOD=POST ACTION=" Selection.jsp ">
The code for Selection.jsp is shown below, with JSP-specifi c content shown in
bold. Note that, if the 'Checkout' option is selected by the user, control is now re-
directed to another JSP (viz., Checkout.jsp ), rather than to servlet Checkout . Note
also how use is made of the implicit object session to store the value of the current
product, without the necessity for creating a Session object explicitly (as was the
case in the selection servlet).
In the servlet-only version of this application, control is then passed to a Weight
servlet. Since this servlet's activities consist entirely of background processing and
re-direction to the next appropriate page, with no Web page output being generated,
this is an ideal opportunity for keeping the servlet. There are one or two minor
changes that need to be made to this servlet (as will be identifi ed shortly) and the
modifi ed servlet will be named WeightX . The reference to this servlet is also shown
in bold type below.
<!-- Selection.jsp -->
<TITLE> <%= currentProduct %> </TITLE>
body{text-align=center; color=blue;}
String currentProduct;
currentProduct = request.getParameter("Product");
if (currentProduct.equals("Checkout"))
<H1><P STYLE=”color:red”> <%= currentProduct %>
Search WWH ::

Custom Search