Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Request Dispatcher interface

Aim:

To create a java application for creating requesting dispatcher interface

Procedure:

 In the index.html page the requesting interface is designed with username


and password.
 Create a servlet and assign the variables of username and password using
String username = request.getParameter(“username”);
String password = resquest.getParameter(“password”);

 Check the valid username and password using


If(username.equals(“1951202”) && password.equals(“MCA”))
{
RequestDispatcher j = request.getRequestDispatcher(“Welcome”);
j.forward(request,response);

else
{
RequestDispatcher j = request.getRequestDispatcher(“error”);
j.forward(request,response);

}
Creating a servlet for cookies

Aim:

To create a servlet that uses cookies to store the number of times a user has
visited a servlet.

Procedure:

 The servlet is created for the cokkie for the cookies visited count by cookie
object.
Cookie = new Cookie (“username”,”1951202”);

 Set the age for the user to visit the site.


 Place the cookie in http response

Response .addcookie(e);

 To count number of times a user visited.

If(j==1)

Out.println(“welcome”);

else

out.println(“you visited “+i+”times”);


Creating a servlet for demonstrating the user of session
execution and destruction

Aim:

To create a servlet to check whether the user has visited the page for the first
time or earlier.

Procedure:

 Create a http session object.


Httpsession Session = request.getsession():

 Store the user information into the session object by using


setattribute() method.

Session.setattribute(“username”,”1951202”);

 To get the value from session we use the getattribute() method.

String username =(string)session.getattribute(“username”);

 Check whether one user has visited this page or visited earlie
using

If(j==1) { out.println(“welcome”);}

else { out.println(“you visited “+i+”times”);}

You might also like