• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

can we retrieve cookie with JSP added thru servlet

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear,
I have added a cookie to the system with the Servlet and now i want to retrieve it thru JSP is it possible .. i have allready tried and ya i can perfectly retrieve it with servlet....
regards,
Rahul Juneja
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer is Yes.
Since JSP's compile into servlets before running, they are the same thing as far as the engine is concerned. Just get the cookie from the request exactly as you would in a servlet.
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have added a cookie to the system with the Servlet and now i want to retrieve it thru JSP is it possible


Sure, no problem. However, remember that the default behavior of cookies is that they get returned by the browser only for requests in the same apparent directory (ie same URL up to the rightmost slash) or in subdirectories. Thus, a cookie sent to http://host/webappPrefix/foo/SomeServlet would not get returned to http://host/webappPrefix/bar/SomeFile.jsp. Use setPath to change this. Eg, the following tells the browser to return the cookie on any request back to the server:

Cheers-
- Marty
 
Good night. Drive safely. Here's a tiny ad for the road:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic