In this lab, you will build a simple To Do list Web application using Java Server Pages. The design will be server-side MVC; that is, almost all processing is done on the server, with the browser used just to display information and take inputs from the user.
In the laboratory sessions, we will be using this online waiting list. Please sign in and add yourself to the list when you need help:
http://www.waglys.com/LxXLKh (Links to an external site.)
The user will be able to login or register as a new user. When the user logs in, their email address and password are checked against known users and, if found, the user's identity is saved in the session object.
Once logged in, the user will see their current list of To Do items. They can add a new item, or edit or delete an existing item. They can then log out.
The web app should look like the following when running:
Note: There are many things that will be suboptimal about the app when you have completed this lab. These will be improved upon in later weeks. In particular:
- The password is sent as plain text over the Internet, and stored in plain text in the server
- We have implemented logout in a way that resets everything. Thus, if you register, logout, then try to log back in, it will fail. We will see how to preserve the user database in a future week, using Persistence.
- There is only one To Do list, shared by all users.
Please download the starting code todo.zip
Open it as a Netbeans project and try to compile and run it. It should compile successfully. You should see the initial screen, and the Register or Login screen; but then trying to register or login will give a server error. (If the code does not compile, or you cannot see the initial screen, please get help before going any farther.)
Look for the places marked //TODO in both the .jsp pages and the .java files. Complete these parts so the app works as specified.
Let's start by getting the login function working. The messages sent from the browser to the server first arrive at FrontController.java. Looking at login.jsp, we see that it sends a message with "action" parameter set to "login", and two other parameters: "email" and "password". Looking at FrontController.jsp, we see that this calls the login() method in Model.java. Looking at this file, we see that login() is not yet implemented. Write this routine, and check that the user can now log in.
Get the other features working one by one in this fashion (don't try to finish the whole app at once). For the other pages that send messages to the server, you will need to extend FrontController by adding more cases in the switch(action) statement, similar to the code for "login".
Improve the look of the page, perhaps using CSS and/or Bootstrap.
Write something more meaningful for the header and the footer.
Take a look at the two unit tests for the model that we provide. Add some more for each feature that you build (before or after you write the code).
The user can currently cheat and see the list even when logged out, by entering the URL "/todo/list.jsp" manually. Change it so that this gives error code 403 when the user is logged out. (Hint: Change the .jsp files, not the Java code.)
Contact a lab assistant to give a demonstration.