You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by 白鹏 <bi...@gmail.com> on 2009/04/06 10:17:08 UTC

[Help] How to pass the parameter of an Interceptor to the Action??

hey,guys,  the code follows,

public class LoginInterceptor extends AbstractInterceptor {

    private String* redirectUrl*;
    public String getRedirectUrl() {
        return redirectUrl;
    }
    public void setRedirectUrl(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }
    @Override
    public String intercept(ActionInvocation arg0) throws Exception {
        System.out.println("Come into the LoginInterceptor#intercept()");
        ActionContext ctx = arg0.getInvocationContext();
        User user = (User) ctx.getSession().get("user");
        if(user!= null){
            return arg0.invoke();
        }
        ctx.put("tip", "请先登录系统:)");
        Map params = ActionContext.getContext().getParameters();
        *redirectUrl* = "*buildSendReq.action*
?productID=11&productTitle=Games+Explorer";
        System.out.println("RedirectUrl="+redirectUrl);

        System.out.println("Intercept() ok!");
       * return Action.LOGIN;  // Login.action ,  I want to pass the
redirectUrl to the Login.action.  How to do ???*
    }

}

Re: [Help] How to pass the parameter of an Interceptor to the Action??

Posted by Terry Gardner <Te...@Sun.COM>.
One idea I have:

1. Create an interface called RedirectAware
2. Have the actions which need the redirectURL implement RedirectAware
3. Inject the redirectURL into Actions that are RedirectAware from the  
interceptor

On Apr 6, 2009, at 4:17 AM, 白鹏 wrote:

> hey,guys,  the code follows,
>
> public class LoginInterceptor extends AbstractInterceptor {
>
>    private String* redirectUrl*;
>    public String getRedirectUrl() {
>        return redirectUrl;
>    }
>    public void setRedirectUrl(String redirectUrl) {
>        this.redirectUrl = redirectUrl;
>    }
>    @Override
>    public String intercept(ActionInvocation arg0) throws Exception {
>        System.out.println("Come into the  
> LoginInterceptor#intercept()");
>        ActionContext ctx = arg0.getInvocationContext();
>        User user = (User) ctx.getSession().get("user");
>        if(user!= null){
>            return arg0.invoke();
>        }
>        ctx.put("tip", "请先登录系统:)");
>        Map params = ActionContext.getContext().getParameters();
>        *redirectUrl* = "*buildSendReq.action*
> ?productID=11&productTitle=Games+Explorer";
>        System.out.println("RedirectUrl="+redirectUrl);
>
>        System.out.println("Intercept() ok!");
>       * return Action.LOGIN;  // Login.action ,  I want to pass the
> redirectUrl to the Login.action.  How to do ???*
>    }
>
> }


======

Terry Gardner
Terry.Gardner@Sun.COM

"Vulcans never bluff." -- Spock


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org