Saturday, 27 August 2011

WT lab Servlets Programs - Week 8

Next week who are having the lab note down the following programms in your observation then come to the lab.
//Program Number 1 for Week 8: SetCookies.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SetCookies extends HttpServlet
{
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
    {
        response.setContentType("text/html");
        PrintWriter pw=response.getWriter();
        Cookie cookie1=new Cookie("09221A0501","09221A0501");
        Cookie cookie2=new Cookie("09221A0502","09221A0502");
        Cookie cookie3=new Cookie("09221A0503","09221A0503");
        Cookie cookie4=new Cookie("09221A0504","09221A0504");
        cookie1.setMaxAge(60*60);
        cookie2.setMaxAge(60*60);
        cookie3.setMaxAge(60*60);
        cookie4.setMaxAge(60*60);
        response.addCookie(cookie1);
        response.addCookie(cookie2);
        response.addCookie(cookie3);
        response.addCookie(cookie4);
    }
}



No comments:

Post a Comment