You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by john lee <sh...@yahoo.com> on 2013/05/24 21:17:25 UTC

struts2 Intercepter Actioncontext


In an cutomized Struts2 Intercepter class, 

    public class SecurityVerifySessionIntercepter extends AbstractInterceptor
          ActionContext actionContext = invocation.getInvocationContext();
          HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
          Map session = actionContext.getSession();

the above program works without any problem

however,

   if i want to access WebApplicationContext, i have to get ServletActionContext first as the following
         WebApplicationContext context=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
   the compile complain can not find ServletActionContext.

   for the regular Struts2 action class extends ActionSupport, then i have no problem to get ServletActionContext, but failed in Intercepter.

Question is:
 
    I already extends AbstractInterceptor for use interceptor, certainly i can not extends ActionSupport any more.
    then how can i access ServletActionContext in the interceptor?
    without extends Actionsupport, can i get ServletActionContext from ActionContext? how to convert?

please advise

john

Re: struts2 Intercepter Actioncontext

Posted by john lee <sh...@yahoo.com>.
could you give more clue ? tks


________________________________
 From: Dave Newton <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org> 
Sent: Friday, May 24, 2013 2:46 PM
Subject: Re: struts2 Intercepter Actioncontext
 

It's a static class.

You may want to brush up on some Java and framework basics before
proceeding too much further-it'll save some time in the long run.

Also note that it's often faster to just try something.

Dave
On May 24, 2013 3:17 PM, "john lee" <sh...@yahoo.com> wrote:

>
>
> In an cutomized Struts2 Intercepter class,
>
>     public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
>           ActionContext actionContext = invocation.getInvocationContext();
>           HttpServletRequest request= (HttpServletRequest)
> actionContext.get(StrutsStatics.HTTP_REQUEST);
>           Map session = actionContext.getSession();
>
> the above program works without any problem
>
> however,
>
>    if i want to access WebApplicationContext, i have to get
> ServletActionContext first as the following
>          WebApplicationContext
> context=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
>    the compile complain can not find ServletActionContext.
>
>    for the regular Struts2 action class extends ActionSupport, then i have
> no problem to get ServletActionContext, but failed in Intercepter.
>
> Question is:
>
>     I already extends AbstractInterceptor for use interceptor, certainly i
> can not extends ActionSupport any more.
>     then how can i access ServletActionContext in the interceptor?
>     without extends Actionsupport, can i get ServletActionContext from
> ActionContext? how to convert?
>
> please advise
>
> john

Re: struts2 Intercepter Actioncontext

Posted by Dave Newton <da...@gmail.com>.
It's a static class.

You may want to brush up on some Java and framework basics before
proceeding too much further-it'll save some time in the long run.

Also note that it's often faster to just try something.

Dave
 On May 24, 2013 3:17 PM, "john lee" <sh...@yahoo.com> wrote:

>
>
> In an cutomized Struts2 Intercepter class,
>
>     public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
>           ActionContext actionContext = invocation.getInvocationContext();
>           HttpServletRequest request= (HttpServletRequest)
> actionContext.get(StrutsStatics.HTTP_REQUEST);
>           Map session = actionContext.getSession();
>
> the above program works without any problem
>
> however,
>
>    if i want to access WebApplicationContext, i have to get
> ServletActionContext first as the following
>          WebApplicationContext
> context=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
>    the compile complain can not find ServletActionContext.
>
>    for the regular Struts2 action class extends ActionSupport, then i have
> no problem to get ServletActionContext, but failed in Intercepter.
>
> Question is:
>
>     I already extends AbstractInterceptor for use interceptor, certainly i
> can not extends ActionSupport any more.
>     then how can i access ServletActionContext in the interceptor?
>     without extends Actionsupport, can i get ServletActionContext from
> ActionContext? how to convert?
>
> please advise
>
> john

Re: struts2 Intercepter Actioncontext

Posted by cantalou89 <ca...@gmail.com>.
In the Intercepter , you can try  
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletConfig.getServletContext());
after you get request.



cantalou89

From: john lee
Date: 2013-05-25 03:17
To: struts support
Subject: struts2 Intercepter Actioncontext


In an cutomized Struts2 Intercepter class, 

    public class SecurityVerifySessionIntercepter extends AbstractInterceptor
          ActionContext actionContext = invocation.getInvocationContext();
          HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
          Map session = actionContext.getSession();

the above program works without any problem

however,

   if i want to access WebApplicationContext, i have to get ServletActionContext first as the following
         WebApplicationContext context=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
   the compile complain can not find ServletActionContext.

   for the regular Struts2 action class extends ActionSupport, then i have no problem to get ServletActionContext, but failed in Intercepter.

Question is:

    I already extends AbstractInterceptor for use interceptor, certainly i can not extends ActionSupport any more.
    then how can i access ServletActionContext in the interceptor?
    without extends Actionsupport, can i get ServletActionContext from ActionContext? how to convert?

please advise

john