ListManager Views
The View classes used by the ListManager
application are JSP pages.
Although the Controller
class can
handle four actions (login, edit, unsubscribe, and logout) the web
application requires only two views, login.jsp
and edit.jsp, which are shown in Examples Example 20-10 and Example 20-11.
login.jsp displays a login form, obviously.
As part of the form, it displays an optional message, specified by the
Controller
servlet with the
HttpServletRequest.setAttribute( )
method. This message explains errors (“Incorrect Password”) or
provides confirmation (“logged out”). The login form has input fields
for an email address and password, and has buttons to log in and edit
an existing subscription or to subscribe a new address to the list.
Whichever button the user clicks, the email address and password are
sent to the “login.action” URL, which is handled by the login( )
method of the Controller
servlet.
The edit.jsp
page includes a form that allows the user to edit his
mail preferences; this form POSTs to the “edit.action” URL, which is
handled by the edit( )
method of
the Controller
. It also includes
buttons that POST to the “logout.action” and “unsubscribe.action”
URLs, which are handled by the logout(
)
and unsubscribe( )
methods of the Controller
.
Note that both login.jsp and
edit.jsp clearly document their inputs and
outputs. This helps integrate these View objects with the action
methods of the Controller
servlet. This technique is particularly helpful for large web ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.