Prerequisites
Skeleton Code
This Magercise illustrates how to handle HTML form processing with
servlets. In addition, it demonstrates how to dynamically create an
HTML display based on data structure information that is processed by
the servlet at run time.
The first servlet, FormDisplayServlet, is written for you.
It takes two parameters, structurefile and datafile.
The first parameter points to a disk file that is a data dictionary
file - it describes the structure of the data to be presented. The
second parameter points to a disk file that contains the actual data.
FormDisplayServlet takes these two parameters and generates
an HTML form on the fly. To the user, it looks like
they have a whole
table full of editable data. When the user presses the form's
button, the form sends the changed data to FormProcessServlet
for processing.
Your task in this Magercise is to complete the development of
FormProcessServlet.
Perform the following tasks:
Change the skeleton code for FormProcessingServlet
to accept data sent from the client to the server. The client
sends an HTTP POST request with a complete set of data from
the HTML form.
Write code in FormProcessingServlet to echo the
accepted data back to the client in the form of an HTML table.
This makes it appear to the user of the browser that they are
seeing a non-editable version of the updated information.
Finally, as an advanced part of this Magercise, write the code
to store the updated data to the disk. This is not a trivial
exercise as you have to think about the problem of multiple
people updating data at the same time.
Request the first form to be displayed by sending the URL
http://localhost:8080/servlet/FormDisplayServlet?
structurefile=struct.dat&datafile=data.dat
The task numbers above are linked to the
step-by-step
help page. Also available
is
a complete solution to the
problem, and a demonstration
of the expected behavior.
When you finish this Magercise you will understand how to handle
HTML FORM processing with servlets.
Copyright © 1998 MageLang
Institute.
All Rights Reserved.
|