Java Reference
In-Depth Information
development of the user interface. The classes in this layer and their rela-
tionship to the session and application context are shown in Figure 16.7.
Class
Manager
is a singleton that provides access to the persistent storage.
It hides all the details of the access to the database through JDBC, in par-
ticular all the SQL queries are inside this class, thus making the JSPs simpler
and cleaner. When the JSP container starts, an instance of
Manager
is
created and a reference to it is stored in the web context (that is accessible
through the variable “application” in JSP). Class
ContextListener
is respon-
sible for this initialization (it opens a database connection). On demand
the manager can load the user profiles from the database. The
User
class
represents the user profiles and is responsible for opening and closing the
connection to the mail server.
Decision point
How do we structure the user interface in order to allow the registration of
new users?
The structure is an extension of the one defined in the previous prototype.
The JSPs that make up the interface use the classes
Manager
and
User
to
simplify their operation. The structure of the user interface is presented in
Figure 16.8.
The upper two elements provide the tools to register a new user.
Register.
html
shows a form with all the details of the profile.
Add.jsp
validates the
submitted information and creates a new user profile in the database. This
mechanism allows anyone to create a profile on the UbiMail system. If
required, these elements can be modified to limit or regulate the subscriptions
to UbiMail.
The login, main and message pages work exactly as in the previous proto-
type. Two new pages are used to edit the profile:
setup
and
update
. The
former shows the user profile and allows its modification, the latter takes the
modified profile and updates the database.
ContextListener
ServletContext
HttpSession
1
1
manager
user
1
1
new
new
Manager
User
Figure 16.7
Basic access layer