File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Cookies with requestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Cookies with requestDispatcher" Watch "Cookies with requestDispatcher" New topic
Author

Cookies with requestDispatcher

Sudarshan Muramreddy
Greenhorn

Joined: Jun 08, 2004
Posts: 16
Hi all,

Is there any way i can send the hearder/cookies information ,when we do forward of request?

if i do sendredirect I can get all the cookies values, which ever i am setting but if i use forward they are lost.

I need to use forward BCOZ i have lots of hidden variables,which need to be passed.

Thanks,
Reddy
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Are u using dispatcher within the same application (or) different application.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Sudarshan Muramreddy
Greenhorn

Joined: Jun 08, 2004
Posts: 16
HI Vishnu ,
I am using in the same application.

Thanks,
Sudarshan
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
try setting the cookie as session attribute.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

When you forward, you're passing the same request object to all resrources.
You shouldn't be losing anything.

What makes you think you are losing those values?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
I think the OP is trying to SET new cookies into the response object.
Of course as a result of forwarding, the response is reset, and none of the cookies are sent.

There is no way around this that I am aware of.
If you haven't done any output you could maybe "include" instead of "forward"
That will keep the cookies that have been set, and append the html output.
In theory anyway ;-)

Cheers,
evnafets
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Of course as a result of forwarding, the response is reset, and none of the cookies are sent.


Umm, no. That is not correct. Forwarding does not reset the response. Any headers set prior to a forward operation remain on the response.
[ November 14, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies with requestDispatcher