Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Cookies on JSP

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , I have have read that you are not allowed to write cookies in a JSP and JSTL does not allow you to write cookies but it does allow you to read them.
Now suppose a user goes directly to a page say "page1.jsp" now page 1 will always redirect to another page.

My question is how can i set a particular cookie at the address of page1.jsp (since the container is calling Page1.jsp directly) so that when ever a user gets to page1.jsp the browser sends the cookie of page1.jsp to it.
The only way i see this to be possible is to create a servlet which sets a cookie and forwards it to page1.jsp. something like this
Container->Servlet->(forward with cookie)->page1.jsp
But i need something like this
Container->page1.jsp(i need to place a cookie here)

a scriptlet could do the task at hand easily like this
<%
Cookie cookie = new Cookie("name","John");
response.addCookie(cookie);
%>
but i dont want to use a scriptlet. What would be the best way to accomplish this task ?? any suggestions ??

 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just do it in the page controller servlet for the JSP.

If you don't know what that is, please read this article.
 
Greenhorn
Posts: 18
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you can use the jsp standard tag libraries .
i am not sure of this tag <jsp:cookie> but there is a way to set cookie from a jsp with out using scriplets.
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no standard action named <jsp:cookie>. And there is no other standard action which deals with cookies. You can get cookie values using EL. But there is no way you can set them in JSP (without using scriptlet). This doesn't mean that go ahead and use scriptlets for setting cookies. Use page controller servlet for the JSP as mentioned by Bear.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic