0% found this document useful (0 votes)
55 views5 pages

Ajp 24

The document contains details of a student project including the student's name, roll number, and practical number. It then includes the code for three Java servlet programs and one HTML program. The first servlet program sets a cookie. The second servlet program gets user input from a form, stores it in a cookie, and displays the cookie values. The third servlet program displays the cookie values. The HTML program contains a login form to collect the user input.

Uploaded by

gmpawar003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views5 pages

Ajp 24

The document contains details of a student project including the student's name, roll number, and practical number. It then includes the code for three Java servlet programs and one HTML program. The first servlet program sets a cookie. The second servlet program gets user input from a form, stores it in a cookie, and displays the cookie values. The third servlet program displays the cookie values. The HTML program contains a login form to collect the user input.

Uploaded by

gmpawar003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name:-Ashwin Pawar

Roll NO:- 23
Practical No :- 24

Program1:-

import java.servlet.*;
import java.servlet.http.*;
import java.io.*;
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 = response.getWriter();
pw.println("<br>");
pw.println("<b>My Cookie has been set to ");
pw.println("<i>" + Data + "</i>");
pw.close();
}
}

OUTPUT:-
Program2:-

import java.servlet.*;
import java.servlet.http.*;
import java.io.*;
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 {
response.setContentType("text/html"); PrintWriter pw =
response.getWriter();
String name = request.getParameter("username");
String password = request.getParameter("password");
Cookie c3 = new Cookie(name, password); response.addCookie(c3);
String p1 = c3.getName(); String p2 = c3.getValue();
pw.println("<br>");
pw.println("<b><center><h2>Student
Information</h2></center></b>");
pw.println("<b><h3>Name: </h3></b>"+ p1);
pw.println("<br>");
pw.println("<b><h3>Password: </h3></b>"+ p2);
pw.println("<br>"); pw.println("");
pw.print("<br><a href ='UserInfo2'>View
Details</a>");
pw.close();
} catch (Exception e) {
System.out.println(e);
}
}
import java.servlet.*; import java.servlet.http.*; import java.io.*;
public class UserInfo2 extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
response.setContentType("text/html"); PrintWriter pw =
response.getWriter();
Cookie c3[] = request.getCookies();
String s1 = c3[0].getName();
String s2 = c3[0].getValue();
pw.println("<b><h3>Name: </h3></b>" + s1); pw.println("<br>");
pw.println("<b><h3>Password: </h3></b>" + s2);
pw.println("<br>");
pw.close();
} catch(Exception e) {
System.out.println(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:-

You might also like