Results 1 to 2 of 2

Thread: seeing cookies

  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default seeing cookies

    I save a current anonymous user at my user-table and create a cookie with the user’s id, so I am able to save some user’s activity into my DB and when the user revisits the site he/ she can be successfully identified.

    But there is a problem when the user does not admit cookies!

    My question is, how I find out if the created cookie has been stored at the client’s computer?

    I tried checking the cookie immediately after the cookie was created, but discovered that you can not see the cookie right away, but “some later” yes!

    Java Code:
    HttpServletResponse response = ServletActionContext.getResponse();
    			Cookie cookie = new Cookie(“whatevername”, "" + id);  
    			cookie.setPath(“/whateverpath/“);
    			cookie.setMaxAge(2592000); // one month 2 629 743.83 seconds?  2592000
    			response.addCookie(cookie);
    			
    			
    			HttpServletRequest request = ServletActionContext.getRequest();
    			System.out.println("is autlogged: " + autoLogin( createdUser, "---", request));
    			
    			//request.getSession().invalidate();
    			//request.getSession(true);
    			Cookie[] cookies = request.getCookies();
    			boolean hasCookie = false;
    			if(cookies != null) {
    				for (int i = 0; i < cookies.length; i++ ) {
    					System.out.println(">>>> " + cookies[i].getName());
    					if (cookies[i].getName().equals(“whatevername”)) {
    						hasCookie = true;
    						break;
    					}
    				}
    			}

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,139
    Rep Power
    13

    Default Re: seeing cookies

    I get one single cookie:

    cookie value: JSESSIONID=9BEAD1117FE2728EC81CA27E5D2E7D21

Similar Threads

  1. Replies: 21
    Last Post: 05-21-2009, 01:53 PM
  2. CooKies and Session
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-27-2009, 01:47 PM
  3. cookies
    By lukky in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 09-02-2008, 07:46 PM
  4. JSP cookies example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:11 PM
  5. cookies question
    By sandor in forum New To Java
    Replies: 1
    Last Post: 05-09-2007, 12:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •