hi,
I am trying to create a servlet that sets a cookie and then
prints the name of the cookie.
The code is given below.
the servlet runs fine but does not give the name of the cookie the first
time.
Only when i refresh it gives the name of the cookie.
Please help me out.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class imp extends HttpServlet{
public void init(ServletConfig config)
throws ServletException{
super.init(config);
}
public void doGet(HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
String name;
res.addCookie(new Cookie("session_id","anurag"));
Cookie[] cookies = req.getCookies();
res.setContentType("text/html");
PrintWriter out =res.getWriter();
out.println("<HTML>");
out.println("<BODY>");
if (cookies != null)
{
for(int i=0;i < cookies.length;i++)
{
name=cookies[i].getName();
out.println(name);
}
}
out.println("the cookies r displayed");
out.println("</body></html>");
out.close();
}
}
Thanks
-anurag
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html