It's not a secret anymore!*
The moose likes Spring and the fly likes How to pass cookies in java spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to pass cookies in java spring" Watch "How to pass cookies in java spring" New topic
Author

How to pass cookies in java spring

rahul markonda
Greenhorn

Joined: Jul 13, 2011
Posts: 9
Hi all,
I have a security issue in my java spring project that uses REST webservices.
I need to pass cookies from one request object to another. Is there a way I can achieve this using Cookie class or any other way?
Thank you.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Why do you need to pass cookies between request. You can always get the cookies from request object. If you want to share some data across request, then you can put the data in session.
rahul markonda
Greenhorn

Joined: Jul 13, 2011
Posts: 9
Hi,
I figured it. I passes the HttpServletRequest object as a parameter and did request.getCookies() to get an array of Cookies.
Then I passed this using.....opps i forgot.....I think I changed the http Cookies to apache Cookies and sent them through the HttpState.addCookies().....if I can remember.
Thank you anyway.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

Alternatively you can map the value from the httpSession using the @CookieValue annotation




Spring will automatically handle the type conversion for you.


If you just want to pass a value from one controller to another in Spring 3.1.1 they finally gave us flash attributes.



[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass cookies in java spring
 
Similar Threads
What would be a proper way of reading a cookie in JSP
want add cookies to make sso
Test Cookies enable/disabled
need to set a param that persists across all pages
SunMicrosystems VS Microsoft