Professional Documents
Culture Documents
(Affiliated to Osmania University) Hyderabad-500 031. DEPARTMENT OF : cse NAME OF THE LABORATORY: Web Programming Name A.Sindhu .Roll No 06098047 .Page No .
EXPERIMENT-12
12.1)programe to demonstrate cookies. Index.html: <html> <head></head> <body> <form method=post action="serv1"> UserName<input type=text name=uname /><br> Age<input type=text name=age /><br> <input type=submit name=continue value=continue /> </form> </body> </html> Sessionservlet.java: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class SessionServlet extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException { String uname,age; uname=req.getParameter("uname"); age=req.getParameter("age"); //Create cookies and send them as response Cookie c1= new Cookie("uname",uname); Cookie c2= new Cookie("age",age); c1.setPath("/"); c2.setPath("/"); //age in seconds c1.setMaxAge(100); c2.setMaxAge(100); //Include them as part of response resp.addCookie(c1); resp.addCookie(c2);