Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we retrieve cookie with JSP added thru servlet

 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • 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
 
Pete Harris
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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.
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!