Code segment: access Cookie

  Abstract: The code segment: access Cookie 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="753" border="0"> <tr> <td> </ td> </ tr> </ table> 
  Protected void setCookie (HttpServletResponse response, String cookieName, String value) ( 
  Cookie cookie = new Cookie (cookieName, value); 

  Cookie.setPath ("/"); 
  Response.addCookie (cookie); 
  ) 

  Protected Cookie getCookie (HttpServletRequest request, String name) ( 
  Cookie [] = cookies request.getCookies (); 
  Cookie returnCookie = null; 

  If (cookies! = Null) ( 
  For (int i = 0; i <cookies.length; i + +) ( 
  Cookie thisCookie [i] = cookies; 

  If (thisCookie.getName (). Equals (name)) ( 
  ReturnCookie = thisCookie; 
  Break; 
  ) 
  ) 
  ) 

  Return returnCookie; 
  ) </ Td> </ tr> <tr> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply