Name:- Rehan Pathan
Roll NO:- 54
Practical No :- 24
Program1:-
import [Link].*;
import [Link].*;
import [Link].*;
public class CreateCookie extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
PrintWriter pw = [Link]();
[Link]("<br>");
[Link]("<b>My Cookie has been set to ");
[Link]("<i>" + Data + "</i>");
[Link]();
}
}
OUTPUT:-
Program2:-
import [Link].*;
import [Link].*;
import [Link].*;
public class UserInfo extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,
IOException {
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
try {
[Link]("text/html"); PrintWriter pw =
[Link]();
String name = [Link]("username");
String password = [Link]("password");
Cookie c3 = new Cookie(name, password); [Link](c3);
String p1 = [Link](); String p2 = [Link]();
[Link]("<br>");
[Link]("<b><center><h2>Student
Information</h2></center></b>");
[Link]("<b><h3>Name: </h3></b>"+ p1);
[Link]("<br>");
[Link]("<b><h3>Password: </h3></b>"+ p2);
[Link]("<br>"); [Link]("");
[Link]("<br><a href ='UserInfo2'>View
Details</a>");
[Link]();
} catch (Exception e) {
[Link](e);
}
}
import [Link].*; import [Link].*; import [Link].*;
public class UserInfo2 extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
[Link]("text/html"); PrintWriter pw =
[Link]();
Cookie c3[] = [Link]();
String s1 = c3[0].getName();
String s2 = c3[0].getValue();
[Link]("<b><h3>Name: </h3></b>" + s1); [Link]("<br>");
[Link]("<b><h3>Password: </h3></b>" + s2);
[Link]("<br>");
[Link]();
} catch(Exception e) {
[Link](e);
}
}
}
HTML PART :
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login form</title>
</head>
<body>
<form action = "UserInfo" method = post>
<center>
<b><h1>Student Login Form</h1></b>
Username:<input type = "text" name = "username"><br><br>
Password:<input type = "text" name = "password"><br><br>
<input type = "submit" value = "Submit"/>
</center>
</form>
</body>
</html>
Output:-