for avtar2008 only II

profilekpecet
project_5.doc

Use the following html document and change the servlet program to write a servlet using cookie class to do the following.

1. A new user enters a name like: John Doe and password: abc the server should responds the page:

image1.png

2. If the name and the password is in the system the servlet should responds:

image2.png

Use the following html document and change the servlet program.

<!-- Main.html -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Project 4</title>

</head>

<body>

<form action="http://localhost:8080/Project/Main">

<center>

<h1> Please Login</h1>

<br><br>

Name:

<input name="name" type="text" value="">

<br>

Password:<input name="password" type="password" value="">

<br><br>

<input name="login" type="Submit" value=" Submit ">

</center>

</form>

</body>

</html>

import java.io.*;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

@WebServlet("/Main")

public class Main extends javax.servlet.http.HttpServlet

implements javax.servlet.Servlet {

public Main() {

super();

}

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException{

String name = request.getParameter("name");

String password = request.getParameter("password");

// Complete the rest of this method.

}

}

Note: The content of the variables: name and password password are the name and the password the user enters. For example if the user enters: John Doe for the name and abc for the password the content of the variable : name is John Doe and the content of the variable: password is abc.

The above html document displays the following page:

image3.png

If I enter: John Doe for the name and abc for the password the page is:

image4.png

Note: The name of your servlet class must be: Main.

Note: Do not make a different html document. Do not change my html. Use it.

Note: Copy/paste your Main.java under the word: Answer.

Answer: