This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass cookies in java spring

 
rahul markonda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic