You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Newton <da...@gmail.com> on 2013/05/15 23:14:17 UTC

Re: Cookie in struts2

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

Dave



On Wed, May 15, 2013 at 4:56 PM, john lee <sh...@yahoo.com> wrote:

>
>
> 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
>
> thanks in advance
>
> john




-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>

Re: Cookie in struts2

Posted by john lee <sh...@yahoo.com>.
thanks, in my program, after i import it, the compile error is gone.



________________________________
 From: Chris Pratt <th...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org> 
Cc: john lee <sh...@yahoo.com> 
Sent: Wednesday, May 15, 2013 4:54 PM
Subject: Re: Cookie in struts2
 


Ah, my bad, you are correct, Dave.

John, like Dave pointed out, you should be using:

import javax.servlet.Cookie;

Cookie[] cookieList = ServletActionContext.getRequest().getCookies();

  (*Chris*)



On Wed, May 15, 2013 at 2:41 PM, Dave Newton <da...@gmail.com> wrote:

(With the caveat that the interface is really for actions, while the OP
>seems to be working inside an interceptor.)
>
>Dave
>
>
>
>On Wed, May 15, 2013 at 5:25 PM, Chris Pratt <th...@gmail.com>wrote:
>
>
>> 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
>>   (*Chris*)
>>
>>
>> On Wed, May 15, 2013 at 2:14 PM, Dave Newton <da...@gmail.com>
>> wrote:
>>
>> > Import the Cookie class, and get the cookies from the request, not the
>> > class of the request?
>> >
>> > Dave
>> >
>> >
>> >
>> > On Wed, May 15, 2013 at 4:56 PM, john lee <sh...@yahoo.com>
>> wrote:
>> >
>> > >
>> > >
>> > > 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
>> > >
>> > > thanks in advance
>> > >
>> > > john
>> >
>> >
>> >
>> >
>> > --
>> > e: davelnewton@gmail.com
>> > m: 908-380-8699
>> > s: davelnewton_skype
>> > t: @dave_newton <https://twitter.com/dave_newton>
>> > b: Bucky Bits <http://buckybits.blogspot.com/>
>> > g: davelnewton <https://github.com/davelnewton>
>> > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>> >
>>
>
>
>
>--
>e: davelnewton@gmail.com
>m: 908-380-8699
>s: davelnewton_skype
>t: @dave_newton <https://twitter.com/dave_newton>
>b: Bucky Bits <http://buckybits.blogspot.com/>
>g: davelnewton <https://github.com/davelnewton>
>so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>

Re: Cookie in struts2

Posted by Chris Pratt <th...@gmail.com>.
Ah, my bad, you are correct, Dave.

John, like Dave pointed out, you should be using:

import javax.servlet.Cookie;

Cookie[] cookieList = ServletActionContext.getRequest().getCookies();
  (*Chris*)


On Wed, May 15, 2013 at 2:41 PM, Dave Newton <da...@gmail.com> wrote:

> (With the caveat that the interface is really for actions, while the OP
> seems to be working inside an interceptor.)
>
> Dave
>
>
>
> On Wed, May 15, 2013 at 5:25 PM, Chris Pratt <thechrispratt@gmail.com
> >wrote:
>
> > 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
> >   (*Chris*)
> >
> >
> > On Wed, May 15, 2013 at 2:14 PM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> > > Import the Cookie class, and get the cookies from the request, not the
> > > class of the request?
> > >
> > > Dave
> > >
> > >
> > >
> > > On Wed, May 15, 2013 at 4:56 PM, john lee <sh...@yahoo.com>
> > wrote:
> > >
> > > >
> > > >
> > > > 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
> > > >
> > > > thanks in advance
> > > >
> > > > john
> > >
> > >
> > >
> > >
> > > --
> > > e: davelnewton@gmail.com
> > > m: 908-380-8699
> > > s: davelnewton_skype
> > > t: @dave_newton <https://twitter.com/dave_newton>
> > > b: Bucky Bits <http://buckybits.blogspot.com/>
> > > g: davelnewton <https://github.com/davelnewton>
> > > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> > >
> >
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits <http://buckybits.blogspot.com/>
> g: davelnewton <https://github.com/davelnewton>
> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>

Re: Cookie in struts2

Posted by Dave Newton <da...@gmail.com>.
(With the caveat that the interface is really for actions, while the OP
seems to be working inside an interceptor.)

Dave



On Wed, May 15, 2013 at 5:25 PM, Chris Pratt <th...@gmail.com>wrote:

> 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
>   (*Chris*)
>
>
> On Wed, May 15, 2013 at 2:14 PM, Dave Newton <da...@gmail.com>
> wrote:
>
> > Import the Cookie class, and get the cookies from the request, not the
> > class of the request?
> >
> > Dave
> >
> >
> >
> > On Wed, May 15, 2013 at 4:56 PM, john lee <sh...@yahoo.com>
> wrote:
> >
> > >
> > >
> > > 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
> > >
> > > thanks in advance
> > >
> > > john
> >
> >
> >
> >
> > --
> > e: davelnewton@gmail.com
> > m: 908-380-8699
> > s: davelnewton_skype
> > t: @dave_newton <https://twitter.com/dave_newton>
> > b: Bucky Bits <http://buckybits.blogspot.com/>
> > g: davelnewton <https://github.com/davelnewton>
> > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> >
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>

Re: Cookie in struts2

Posted by Chris Pratt <th...@gmail.com>.
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
  (*Chris*)


On Wed, May 15, 2013 at 2:14 PM, Dave Newton <da...@gmail.com> wrote:

> Import the Cookie class, and get the cookies from the request, not the
> class of the request?
>
> Dave
>
>
>
> On Wed, May 15, 2013 at 4:56 PM, john lee <sh...@yahoo.com> wrote:
>
> >
> >
> > 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
> >
> > thanks in advance
> >
> > john
>
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits <http://buckybits.blogspot.com/>
> g: davelnewton <https://github.com/davelnewton>
> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>