Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Cookies After actionMapping.findForward("")

 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

In my application i am doing search and putting search criteria into the cookies in my struts action class. This class set this values into the cookie and then forward with





The "searchsucccess" leads us to a jsp page.
Now i want the jsp page to retrieve those cookies values in it which i have set in action class like:




But these are coming as null. Like cookies has not been created anywher.

Anybody has any idea.
Regards.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not be able to read the cookies until a round trip to and from the client has been made.

A forward takes place, entirely, on the server without involving the browser so the cookies that you set won't actually exist until the browser receives the response and stores them. When the browser makes it's next request, it will include the cookies in the request headers and you will be able to read them by calling request.getCookies.

If you want to work with those variables from within the same request/response cycle, you might want to also bind them to request scope with request.setAttribute. You will then have access to them from all the components in your request/response chain.
[ February 14, 2008: Message edited by: Ben Souther ]
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben
If i use redirect=true can it work or not?
I mean any way to send any response to browser and still having cookies?
Regards.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using cookies to transfer the data? That's really really odd.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear's question is valid and should be answered.

To answer yours, yes, sendRedirect involves a round trip to the browser and an entirely new request.
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,Bear

You people are right that is the most awkward way of doing the things.
But i have been ordered to that as i am not the senior most person in my company and i have to obey the things.

Now coming to my question:

in my struts-config.xml file i am using redirect="true" like:

>forward name="searchsuccess" path="/admin/showStones.do?dispatch=search" redirect="true" />

but still no the next page i am not able to retrieve the cookies values.
Is there anything else i need to do in my case.
Regards.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic