Skip to main content.

Lab 3: Servlets

Goals

At the completion of this lab, you should be able to

Set up

  1. For this assignment, create a new Dynamic Web project called "Lab3".
  2. Create an index.html page that will have links to each of the next pages (e.g., the login page and the sandwich page).

Login Servlet

For this part of the lab, you will create a login page/form and a servlet that handles responses from that page.

  1. Create a login page (an HTML 5 document) that contains a form that has input fields and labels for a username and password.
  2. Create a servlet that handles requests from the login page. If the user enters the valid username of "username" and password of "passw0rd", the servlet displays a "Congratulations!" response. Otherwise, the servlet returns an error message and provides a link for the user to try again.

Sandwich Servlet

For this part of the lab, you will create a page that responds to your custom sandwich form.

  1. Copy your lab2_form.html file (and its CSS file) into the WebContent directory of your Lab3 project. Name the file sandwich.html.
  2. Create a servlet that handles requests from this form. The response page from the servlet should contain the following content, in the following order:
    • The user's name as a heading.
    • if the order is for here or to go
    • The sandwich's base, bread, and cheese. Examples:
      turkey sandwich on wheat with Swiss cheese
      veggies sandwich on roll with no cheese
    • The condiments and veggies. If the user did not specify any condiments or veggies, put "plain". (How will you know if the user did not request any?)
    • The user's comments/instructions.
  3. Modify your sandwich.html form to point to the approriate servlet.

So, in the end, your servlet will return a page that looks something like the following (although it may not have the same CSS styles):

Smith's Order

For here.

ham sandwich on white with Swiss cheese

lettuce tomato pickles

User Comments:

Links on index.html

Make sure that the index.html page has links to both parts of the assignment.

Turning in the Assignment

To turn in this assignment, export a .war file called lab3.war from your project using Eclipse. (Include source files in the .war file.) Then, copy the .war file into your turnin directory for this course. (/csdept/local/courses/cs335/turnin/yourusername/) Typically, you wouldn't include source files (you just give people your .class files), but for this course, you will include source files.

You would put the generated .war file into Tomcat's webapps directory for deployment. Tomcat will automatically extract the web application from the file. Later this semester, you'll create .war files to put on servo for each project.

Grading (100 pts)

Due tonight at midnight.