Exercise 1 : Additional Lab Exercise

Note : This lab is not mandatory, it is there if you would like to take things further. There is little or no sample code although it is suggested that you use the code from the initial lab exercise as a starting point.

Using a session

Take the original basic servlet which printed a message to the user and amend it to display the number of times the user has visited the page. For this you will need to use the HttpSession class and a good starting point is the Javadoc for that class. It is a good idea to create a new servlet called SessionServlet for this lab exercise.

When the user first visits the page the servlet will create a new session and associate it with this user. Each subsequent time the user visits the page the servlet will display a page count. Try viewing the same servlet from different browsers, notice the different page counts.

Extensions

Ask the user for the password before creating the session.
 


© Steve Ferris 2000