top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Cookie in struts2

0 votes
322 views

I have no difficulty to handle cookie in struts 1, but have lots of error in struts 2

i have the following program

public class SecurityVerifySessionIntercepter extends AbstractInterceptor implements ServletResponseAware, ServletRequestAware {
....

Map session= ActionContext.getContext().getSession();

Cookie cookieList[]=HttpServletRequest.getCookies();

for above program, the compiler give so much error about cookie.

cannot find symbol
symbol  : class Cookie
location: class SecurityVerifySessionIntercepter
          Cookie cookieList[]=HttpServletRequest.getCookies();

non-static method getCookies() cannot be referenced from a static context
          Cookie cookieList[]=HttpServletRequest.getCookies();

please advise

posted May 15, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Import the Cookie class, and get the cookies from the request, not the class of the request?

answer May 15, 2013 by anonymous
thanks, in my program, after i import it, the compile error is gone.
0 votes

You might want to look into the CookiesAware interface. It's a better way of accessing cookies. Here's a good post on handling Cookies in Struts 2: http://omkarp.blogspot.com/2007/07/working-with-cookies-in-struts2.html

answer May 15, 2013 by anonymous
...