拦截器调用后未填充Struts 2动作变量。 [英] Struts 2 action variables not populated after interceptor's invocation.invoke()

查看:75
本文介绍了拦截器调用后未填充Struts 2动作变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,在使用invocation.invoke从拦截器中触发了动作的变量后,该变量没有被填充。我所知道的是,在使用拦截器之前,它可以正常工作(我从.jsp提交了一个表单,然后调用了一个动作,并且填充了每个变量)

My Problem is that the action's variables are not being populated after it is triggered from the interceptor using invocation.invoke. What i know is that before using an interceptor , it worked properly (From a .jsp i submitted a form and an action is called and every variable was populated)

Interceptor类:

Interceptor class:

public String intercept(ActionInvocation invocation) throws Exception {

    final ActionContext context = invocation.getInvocationContext();
    HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
    HttpSession session = request.getSession(true);
    Object user = session.getAttribute(Constants.USER_HANDLE);

    if (user == null) {
        String signUp = request.getParameter(Constants.SIGN_UP);

        if (!StringUtils.isBlank(loginAttempt)) {
            if (processLoginAttempt(request, session)) {
                return "login-success";
            }
        } else if (!StringUtils.isBlank(signUp)) {
            return invocation.invoke();
        }
        return "login";
    } else {
        return invocation.invoke();
    }
}

Struts XML文件:

Struts XML file :

<package name="defaultPackage" extends="struts-default">

    <interceptors>
        <interceptor name="login" class="com.spiddan.LoginInterceptor" />
        <interceptor-stack name="defaultStack">
            <interceptor-ref name="login"/>
        </interceptor-stack>
    </interceptors>

    <default-interceptor-ref name="defaultStack"/>
    <default-action-ref name="index"/>

    <global-results>
        <result name="login" type="redirect">/logIn.jsp</result>
        <result name="login-success" type="redirect">index</result>
    </global-results>

    <action name="addUserAction" class="com.spiddan.action.UserAction" method="addUser">
        <result name="input">/logIn.jsp</result>
        <result name="success">/index.jsp</result>
        <result name="error">/error.jsp</result>
    </action>

动作类别:

public class UserAction extends ActionSupport implements ModelDriven {

private User user;
private int tempGender;
private String confirmPassword;
private UserDAO userDAO;
private PasswordEncrypter passwordEncrypter;

public Object getModel() {
    return getUser();
}

public String addUser() throws Exception {

}

 //Getter and setters ect 


推荐答案

您仅在代码中指定了自定义拦截器,并排除了其他所有拦截器Struts2默认拦截器。改为尝试以下操作:

You've specified only your custom interceptor in your code and have excluded all the other Struts2 default interceptors. Try this instead:

<interceptors>
    <interceptor name="login" class="com.spiddan.LoginInterceptor" />
    <interceptor-stack name="defaultStackModified">  <!-- name doesn't override existing defaultStack-->
        <interceptor-ref name="defaultStack"/>       <!-- include the defaultStack this way--> 
        <interceptor-ref name="login"/>
    </interceptor-stack>
</interceptors>

这篇关于拦截器调用后未填充Struts 2动作变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆