0% found this document useful (0 votes)
1 views1 page

Java 24

The document outlines a practical exercise for implementing session tracking using cookies in a Servlet program. It includes HTML code for a form to submit a value and Java code for a Servlet that processes the form submission by creating and setting a cookie. The output confirms that the cookie has been successfully set with the submitted value.

Uploaded by

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

Java 24

The document outlines a practical exercise for implementing session tracking using cookies in a Servlet program. It includes HTML code for a form to submit a value and Java code for a Servlet that processes the form submission by creating and setting a cookie. The output confirms that the cookie has been successfully set with the submitted value.

Uploaded by

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

Practical No.

24: Write a Servlet program to implement session tracking


using Cookies.
XIII. Exercise:
Develop a program to retrieve value using Cookie.
HTML CODE: -
<html>
<body>
<center>
<form name="Form1"
method="post"
action="http://localhost:8080/examples/servlet/AddCookieServlet">
<B>Enter a value for MyCookie:</B>
<input type=textbox name="data" size=25 value="">
<input type=submit value="Submit">
</form>
</body>
</html>
Servlet CODE :-
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException {
String data = request.getParameter("data");
Cookie cookie = new Cookie("MyCookie", data);
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}}
OUTPUT: -

You might also like