wood burning stoves 2.0*
The moose likes Struts and the fly likes Cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cookies" Watch "Cookies" New topic
Author

Cookies

chris locke
Greenhorn

Joined: Aug 13, 2010
Posts: 17
Hi gurus,

With basic servlets I can usually get away with the code:

HttpSession session = request.getSession();
if (session.isNew()) {
...
}

When throwing struts2 into the mix, I see various ways to add cookies. What is the best way to do this? ie. What is considered best practice? Should I be implementing cookiesAware? Some have suggested Struts2 isn't very good with cookies, so it's better not to use it at all? Others have suggested the use of "ActionContext.getContext().getSession()" to Map your new cookie?

Thanks in advance
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Your action can implement ServletRequestAware to get access to the HttpServletRequest object. From that you can get the HttpSession object...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How is S2 "not very good with cookies"? What would that even mean? What does the session have to do with it; cookies are in the request/response, no?

CookiesAware is the appropriate way to get access to cookies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies
 
Similar Threads
Struts2
Working with Struts2
Struts2
struts2
struts2