Java Reference
In-Depth Information
8.5 (i) Remove (or rename) the Selection servlet from the last task and then copy
Selection.java , Weight.java and Checkout.java from Sect. 8.8 into the
classes folder.
(ii) Add the appropriate tags to your deployment descriptor and compile the
three servlets.
(iii)
Start up Tomcat (stopping it fi rst, if it is already running) and then access
ShoppingCart.html via your browser. Experiment with this simple shop-
ping cart application.
8.6 Extend the above application to cater for selection of bananas, as well as apples
and pears.
8.7 Further extend the above application to allow the user to enter his/her name the
fi rst time only that he/she accesses the home page during a given session.
Achieve this by redirecting the user on this fi rst occasion to a simple HTML
page called GetName.html that accepts the name and then passes control back
to the Selection servlet. Ensure that the user's initial selection is still stored in
the session, as well as his/her name and any subsequent selections. Display the
user's name in the checkout heading.
8.8 (i)
Copy CookieAdder.html into your Web app's root folder. Then copy
CookieAdder.java ,
GetPreferences.java and ShowSum.java into the
classes folder
(ii) Add the appropriate tags to your deployment descriptor and compile the
three servlets.
(iii) Start up Tomcat (stopping it fi rst, if it is already running) and then access
the above Web page via your browser. Experiment with differing input to
the Web page. Notice that you will not be permitted to change your prefer-
ences immediately after entering them. However, since the cookies will
'time out' after a minute, you will be able to experiment with other values
if you wait for this timeout and then re-load the initial page.
(iv) Modify ShowSum.java so that the result page shows either the date and
time of the user's last visit to the page or, if it is the user's fi rst visit, a mes-
sage to indicate this. [Use new to create a Date object (package java.util)
and the Date object's toString method to place the date value into a
cookie.] Re-compile the servlet.
(v) Stop Tomcat, re-start it and then re-test the above application with the
modifi ed servlet.
Search WWH ::




Custom Search