Java Reference
In-Depth Information
For the exercises below, it would be appropriate to create one or more Web applica-
tions. (One would be quite suffi cient, but you might choose to create a separate one
for each exercise.)
9.1 Write a JSP that simply displays the current date and time when it is opened.
9.2 Create a simple HTML page containing a single button that takes the user to a
JSP called Count1.jsp . Now create a JSP with this name that uses a session
variable (i.e., an attribute set up by object session ) to display the number of
times that the user has visited the page during this session. Add a button that
takes the user back to the HTML page.
Extend Count1.jsp (copying and renaming it as Count2.jsp ?) so that the appli-
cation object is used to display the total number of times that the page has been
visited by anybody (in all sessions). If you use a name for the JSP that is differ-
ent from the one used in the previous question, remember to modify the initial
HTML page (copying and renaming it?) so that pressing the button takes the
user back to the correct JSP. When testing this program, open up two browser
windows and observe the difference between the two counts in each pair and
the difference between the contents of the two windows.
9.4 There is now too much Java code in the JSP of the previous exercise and this
should really be moved to a servlet. Introduce a servlet that will do the back-
ground processing and then redirect control to the (reduced) JSP.
Re-write PersonalServlet (and its associated HTML page) from Chap. 8 so that
a JSP is used instead of the servlet. (Use the implicit object request .)
9.6 Create an error page for the above JSP that displays a meaningful error mes-
sage and allows the user to re-enter his/her name if no name was entered ini-
tially. Modify the original JSP so that (a) it registers the error page and (b) it
throws a general Exception object if no name is entered by the user. (Once
again, remember to modify the original HTML page to refl ect any name change
in your JSP.)
Re-write AdderServlet (and its associated HTML page) from Chap. 8 so that a
JSP is used instead of the servlet. Create an error page that displays a meaning-
ful error message if non-numeric data is entered and allows the user to re-enter
the values.
(i) Create three Exception classes (using extends Exception ) that cor-
respond respectively to the following error situations:
the fi rst of the operands in the preceding exercise being non-numeric;
the second being non-numeric;
both being non-numeric.
Search WWH ::

Custom Search