Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Struts2 拦截器阻止URL参数传递给操作_Struts2_Interceptor - Fatal编程技术网

Struts2 拦截器阻止URL参数传递给操作

Struts2 拦截器阻止URL参数传递给操作,struts2,interceptor,Struts2,Interceptor,我有一个LoginInterceptor,它在大多数操作之前运行,并检查成员是否登录。如果是,则显示页面,否则将重定向到登录页面 但是我注意到拦截器“阻塞”了所有URL参数。基本上,如果在一个操作之前有一个拦截器,那么这个操作的URL参数将不会传递给setter 这是我的拦截器: public class LoginInterceptor extends AbstractInterceptor { public String intercept(final ActionInvocatio

我有一个LoginInterceptor,它在大多数操作之前运行,并检查成员是否登录。如果是,则显示页面,否则将重定向到登录页面

但是我注意到拦截器“阻塞”了所有URL参数。基本上,如果在一个操作之前有一个拦截器,那么这个操作的URL参数将不会传递给setter

这是我的拦截器:

public class LoginInterceptor extends AbstractInterceptor {
    public String intercept(final ActionInvocation invocation) throws Exception {
        final String REDIR = "loginRedirect";
        AuthenticationService auth = new AuthenticationService();
        if (auth.isMemberLoggedIn()) {
            return invocation.invoke();
        } else {
            return REDIR;
        }
    }
}
我怀疑
invocation.invoke()
调用了操作,但没有参数

我能怎么办

更新:

AuthenticationService.isMemberLoggedIn()


如果拦截器堆栈不包括
参数
拦截器,则会出现此问题。您应该按照以下方式配置堆栈:

       <interceptors>
           <interceptor name="loginInterceptor" class="community.interceptor.LoginInterceptor" />
           <interceptor-stack name="customDefaultStack">
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="loginInterceptor"/>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="multiselect"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
                </interceptor-ref>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="customDefaultStack"/>

dojo\..*、^struts\..*、^session\..*、^request\..*、^application\..*、^servlet(请求|响应)\..*、参数*
输入、返回、取消、浏览
输入、返回、取消、浏览
或者,您可以扩展开箱即用堆栈:

       <interceptors>
           <interceptor name="loginInterceptor" class="community.interceptor.LoginInterceptor" />
           <interceptor-stack name="customDefaultStack">
                <interceptor-ref name="loginInterceptor"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="customDefaultStack"/>


这里有点不对劲。你能分享你的
auth.isMemberLoggedIn()的代码吗?另外,要明确的是,您的问题不是重定向发生时参数消失了,而是调用操作时参数消失了,对吗?没错。我认为没有必要共享
isMemberLoggedIn()
函数的内容。它很好用。这仅仅是因为测试通过了,
invocation.invoke()
被称为参数“消失”。我要求查看它的内容,因为我认为它正在以某种方式访问HttpServletRequest,在这种情况下,如果操作不正确,它可能是罪魁祸首。但是如果你确定,那么不要;不包括在内。但是,您能从struts.xml中包含拦截器堆栈配置吗?缺少的参数也可能是由于
params
拦截器意外地没有包含在堆栈中。呃,可能是这样的:我没有包含
params
。。。但它不应该被默认包括在内吗?
<interceptor-ref name="loginInterceptor" />
       <interceptors>
           <interceptor name="loginInterceptor" class="community.interceptor.LoginInterceptor" />
           <interceptor-stack name="customDefaultStack">
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="loginInterceptor"/>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="multiselect"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
                </interceptor-ref>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="customDefaultStack"/>
       <interceptors>
           <interceptor name="loginInterceptor" class="community.interceptor.LoginInterceptor" />
           <interceptor-stack name="customDefaultStack">
                <interceptor-ref name="loginInterceptor"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="customDefaultStack"/>