FILS, English Stream, Year 4

Course: Web Application Development

Prof. Luca Dan Serbanati

 

Fifth Laboratory

 

Using Cookies

 

Check out your cookie files in IE and Netscape. On IE, start at the Tools menu, then do Internet Options, General, Settings, View Files. It is easier to find the cookie files if you do “Delete Files” first. On Netscape, do a search (“Find”) for a file called cookies.txt in a Netscape folder. See if you notice a cookie from doubleclick.net in both cases. Take a look at the structure of these files to see if you can figure out how they represent the various cookie parameters.

 

1. Write a servlet that returns an image (reading it from the disk). Since you will be sending binary data, use getOutputStream instead of getWriter to get the stream that sends the image. Use the appropriate MIME type. This one is probably too hard unless you already know how to read files from disk.

 

2. Make a servlet that says “Welcome aboard” to first-time visitors and “Welcome back” to repeat visitors. First verify that it works within a browsing session, then quit your browser and restart to verify that the cookie is persistent on disk.

 

3. Repeat the previous exercise, but with session cookies, not persistent cookies. Visit it twice in Internet Explorer, then click on the IE icon on the desktop to start a new browser. Is this considered the same session or a new one? Repeat the process with Netscape. Notice that they work differently.

 

4. Write a servlet that displays the values of the firstName, lastName, and emailAddress request parameters. If a parameter is missing and the client is a first-time visitor, have the servlet list “Unknown” for the missing values. If a parameter is missing and the client is a repeat visitor, have the servlet use previously-entered values for the missing values.

 

Session Tracking

 

1. Make a servlet that says “Welcome Aboard” to first-time visitors (within a browsing session) and “Welcome Back” to repeat visitors. Was this servlet harder or easier than the equivalent version using cookies explicitly?

 

2. Write a servlet that displays the values of the firstName, lastName, and emailAddress request parameters. Have the servlet list “Unknown” for missing values of first-time visitors and the previously entered values for repeat visitors. This should definitely be easier than the version that used cookies explicitly.

 

3. Make an HTML form containing a textfield and a submit button, where the textfield is intended to gather the name of an item to be purchased. Every time you submit an item, have the servlet show a table or list containing that item plus all previously “purchased” items.