HTML forms page at w3schools
This project has 3 servlets and each one has an associated
stylesheet. The servlets are the drivers and are responsible
for processing user requests and preparing the response data,
while the stylesheets are responsible for rendering that data
The servlets communicate information to the stylesheets via
XML data and stylesheet parameters, while the stylesheets
communicate data to the servlets via HTTP request parameters.
The login servlet demonstrates:
- retrieving and storing session data (the "username"
- invalidating a session
- retrieving HTTP request parameters (the "username",
"password", and "submit" parameters)
- interacting with the back-end UserManager instance to
maintain data associated with a user. Note that the
UserManager provides additional services that you'll need
to access in the view and prefs servlets.
- invoking Xalan by way of TrAX and providing both
XML data and parameters. In this case the XML data is
provided as a file (and is not used by the stylesheet),
but other formats like String are also possible. The
parameter that's passed to the stylesheet is "error".
The login stylesheet demonstrates:
- rendering an HTML page from XML input data and
- the inclusion of an HTML form to accept user input
data which is communicated to the login servlet via an HTTP
POST request, with HTML input parameters named "username",
"password", and "submit", which are communicated to the
servlet as HTTP request parameters.
(Note that though the Login page is operational as distributed,
it redirects to the View servlet, which doesn't contain any code!)
The "view" part of the application needs to present hyperlinks
to headlines in some category, and some means for the user to
navigate to the headlines from his other favorite categories,
via links to the view servlet, and some means to navigate to
the view and prefs pages. You'll need to determine how the
view servlet will behave when it receives a request that
doesn't contain a category (e.g., implement some mechanism for
tracking the last category the user displayed and use that, or
arbitrarily pick one of the user's preferred categories, or
redirect to the prefs servlet if the user hasn't chosen any
categories, or pick an arbitrary category, etc.)
The "prefs" part needs to display the categories within some
channel, and offer some way for the user to navigate to a
display of the categories from a different channel, via links
to the prefs servlet, and some means to navigate to the view and
login servlets. In addition, the user must be offered a way
to add or remove any of the displayed categories from his
list of favorites, with an HTML form that constructs a set
of checkboxes via "input" tags, or maybe a list constructed
from a "select" tag, with "option" tags representing each
category. Note that one of the design issues here is deciding
how to deal with the removal of categories. This requires
some thought, since only "checked" or "selected" categories
will be posted to the servlet as request parameters. There
are a number of possible approaches.
Remember that the XML data you construct must take reserved
characters into account by encoding them as entity
references. Note also that URLs have special characters
that must be URL-encoded. URL encoding is generally handled
automatically by the browser (converting spaces to plus signs
for instance), however the ampersand, along with a few others,
is a special case in that it has special meaning in the query
string portion of GET requests. A hyperlink that looks like this:
results in an HTTP GET request for "doSomething" at www.blah.com,
with parameters "param1" and "param2". The parameters are
encoded within the "query string" of the URL, which starts with
the question mark, and parameters are delimited by ampersands.
If you need to insert a literal ampersand into one of the parameter
values, it must be URL-encoded as %26, where 26 is the hexadecimal
representation for an ampersand in the ASCII character set. For
example, if you needed to set the value of param1 to "you&me",
you'd have to do it like this:
If you didn't encode the ampersand you'd end up with three request
parameters: param1=you, me=, and param2=xyz.
The JDK provides a class to perform URL encoding, java.net.URLEncoder,
which you can see in action in the project's NewsProvider class. XSLT,
on the other hand, does not provide any convenient mechanism for URL
endoding/decoding. One possible route is to call out to the Java
URLEncoder class from within a stylesheet, but this is accomplished
differently by different XSLT processors, and it's probably easier
to account for the problem in the servlets.
In particular, Moreover may have category and channel names that
contain ampersands, so be prepared.
Finally, for those of you having trouble visualizing what this
portal might look like, here are two example pages that might help:
You can do better!