This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving Cookies After actionMapping.findForward("")  RSS feed

 
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.
 
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.
 
Author and ninkuma
Marshal
Posts: 66684
167
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
 
Squanch that. And squanch this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!