Hi,
1. I have used the code below to get hold of the cookie concept. I am using
JWS1.1.3. I took ideas from Jason's book(its explained really well). I am
submitting a form using GET method . A servlet runs in response to form
submission. This servlet checks whether a cookie with name "sessionid" is
sent from the client. If it finds it, then it displays a message 'cookie
recieved from ur PC' else if it does,nt find any cookie with name
"sessionid" from the client, it sends one to the client with message
'cookie has been set on ur PC'.

2. I observed that a file sk.txt gets created in JWS's root
directory(JavaWebServer1.1.3). It contains encrypted data like
-919119932375905. I suspect that this is the file which JWS creates for any
cookies. Can somebody confirm this ? Few related questions are

3. Does the browser chooses the file name for cookies , or the servlet
sends it to the browser. I think this is the functionality of the browser.
The browser sees cookies in response headers, and stores them on the client
PC with some random file name.

4. Why does the cookie file gets created in the JWS installation directory
? The client does not have JWS installed! So by default cookie should get
stored in c:\windows\cookies if I am running Win95 or in some other system
directory for other operating systems. Finally , I think "browser controls
where cookie will be stored"

Can somebody share his experiances over my doubts ?

-mukul

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    response.setContentType("text/html");
    boolean cp = false;;
    String sessionid = null;
    Cookie[] cookies = request.getCookies();
    if(cookies != null)
    {
      for(int i=0; i < cookies.length; i++)
      {
        if(cookies[i].getName().equals("sessionid"))
        {
          sessionid = cookies[i].getValue();
          cp = true;
          break;
        }
      }
    }
    if(sessionid == null)
    {
      sessionid = generateSessionId();
      Cookie c = new Cookie("sessionid",sessionid);
      response.addCookie(c);
    }

    PrintWriter out = new PrintWriter (response.getOutputStream());
    out.println("<html>");
    out.println("<head><title>cookieServlet</title></head>");
    out.println("<body>");
    if(cp == true)
    {
      out.println("<h3>cookie recieved from ur PC</h3>");
    }
    else
    {
      out.println("<h3>cookie has been set on ur PC</h3>");
    }
    out.println("</body></html>");
    out.close();
}

___________________________________________________________________________
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

Reply via email to