简体   繁体   English

登录拦截器(自定义拦截器)清除操作参数

[英]Login Interceptor(Custom Interceptor) clearing the Action Parameters

Here is the interceptor code:- 这是拦截器代码:

public class LoginInterceptor extends AbstractInterceptor implements
    StrutsStatics {
/**
 * 
 */
private static final long serialVersionUID = 1L;

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = invocation.getInvocationContext();
    HttpServletRequest request = (HttpServletRequest) context
            .get(HTTP_REQUEST);
    HttpSession session = request.getSession(false);

    String loginId = (String) session
            .getAttribute(Constants.SESSION_ATT_USERID);

    if (loginId == null) {
        return Action.LOGIN;
    } else {
        return invocation.invoke();
    }

}
}

When calling any particular Action the Interceptor is been called. 调用任何特定动作时,都会调用拦截器。 But the parameters of the Action is getting null. 但是操作的参数为空。 If running the code without interceptor, then its working fine. 如果运行没有拦截器的代码,则其工作正常。 I tried resolving this from many ways but couldn't find any solution. 我尝试通过多种方式解决此问题,但找不到任何解决方案。

When you want to use an Interceptor, you need to ADD it to the defaultStack, or to a customStack of your, while you have most likely used ONLY that Interceptor for your action. 当您想使用拦截器时,需要将其添加到defaultStack或您的customStack中,而您极有可能仅使用该拦截器来进行操作。 This means that any other Interceptor is not running for that action invocation, not even the Parameter Interceptor, that is responsible for setting the parameters in the action. 这意味着没有任何其他Interceptor正在为该动作调用运行,甚至没有参数Interceptor负责在动作中设置参数。

Wrong: 错误:

<action name="foo" class="org.foo.bar.foobarAction">

    <interceptor-ref name="myLoginInterceptor"/>

    <result>success.jsp</result>
</action>

Right: 对:

<action name="foo" class="org.foo.bar.foobarAction">

    <interceptor-ref name="myLoginInterceptor"/>
    <interceptor-ref name="defaultStack"/>

    <result>success.jsp</result>
</action>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM