source: http://www.javapassion.com/handsonlabs/servletbasics/#Homework_Exercise

Lab: 07


Objective

To implement a simple servlet, fetch information from HTML forms and parse the headers populated by the client's browser.

Implementation

Exercise 1: Build and run HelloWorld Servlet Application

  1. Download the sample code.
  2. Open hello2 NetBeans project. 
  3. Build (F11) and run (F6) hello2 project.

running sample

  1. Double click GreetingServlet.java under hello2->Source Packages->servlets to open in the source editor.
  2. Modify the code such that it asks for your hobby.
  3. Modify ResponseServlet.java under hello2->Source Packages->servlets such that it fetches the information sent from the client and displays on the screen

running sample

Exercise 2: Write an application that fetches the HTTP Headers sent by the browser

  1. Write a Servlet or modify the sample code such that it fetches the following headers from the client's browser and displays them in the form of an .html page.
    1. HTTP Method
    2. Request URL
    3. Protocol
    4. Client's IP Address
    5. Content type supported by the browser
    6. List of all headers sent by the browser

Exercise 3: Write an application that accesses the MySQL database server

  1. Write a Servlet or modify the sample code such that it fetches all the country names along with their population from the MySQL database server (as done in the previous lab) and lists them in a table within an .html page.

Exercise 4: Implement an application that utilizes session tracking

  1. Modify exersice 3 in such a way that the user has to login to access the list of all countries.
    1. Create a login servlet that asks the username for his/her password.
    2. Store that information in the session object.
    3. Direct the user to the servlet that lists the countries.
      1. If the user is logged in (i.e. the session objects maintain the correct password) then list the countries.
      2. Otherwise, redirect the user to the login page.

Instructions for submitting your work

  1. You are required to demonstrate your implementation during the lab.
  2. Create an archive (.zip) of your project folder and submit it online.

Last updated: 25th November, 2007