get/set Cookies


/ Published in: Java
Save to your folder(s)

Simple snippet on how to get/set a cookie


Copy this code and paste it in your HTML
  1. // retrieve cookies
  2. Cookie[] cookies = request.getCookies();
  3.  
  4. for(int i=0; i < cookies.length; i++) {
  5. Cookie c = cookies[i];
  6.  
  7. if (c.getName().equals("theCookieImLookingFor")) {
  8. String cookieValue = c.getValue();
  9. }
  10. }
  11.  
  12. // ...
  13.  
  14. // set a new cookie
  15. Cookie myCookie = new Cookie("name", "value");
  16. response.addCookie(myCookie);

URL: http://www.commentcamarche.net/servlets/servcookie.php3

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.