Web Programming
Todo Web Application (Sessions)
The objective of this exercise is to use sessions for user logins.
Tasks
-
Create the server page
login.jsp which contains a form that allows a user to log in or to register.
(Hint: Use the value attribute of the submit buttons to distinguish the two actions.)
-
Implement the
UserAdminServlet that uses the user service to provide the following methods:
doGet forwards the request to the todo list if a user is logged in; otherwise, it forwards it to the login page
doPost logs in or registers a user: on success, a session with the username is created and the browser is redirected to the todo list; on failure, an error message is displayed on the login page
Make the servlet available at the path /userAdmin.
-
Modify the
TodoListServlet and the NewTodoServlet so that they use the todos of the logged-in user stored in the session.
-
Define
userAdmin (without slash) as welcome file in the deployment descriptor web.xml.
-
(Optional) Add the name of the logged-in user to the title of the server page
todoList.jsp.
-
(Optional) Add a button to the sever page
todoList.jsp that sends a logout request to the UserAdminServlet which invalidates the session.
Solution