struts2错误丢失了

时间:2011-10-06 18:35:40

标签: validation struts2

我尝试使用struts2验证框架。我有一个ActionName-validation.xml。 struts.xml中的条目如下

    <action name="registerCandidateStep1" class="candidateAction"
            method="registerCandidateStep1">
            <result name="success" type="tiles">registerCandidate</result>
            <result name="input" type="chain">
                <param name="actionName">loadCandidateRegistrationForm</param>
                <param name="namespace">/.secureActions</param>
            </result>
        </action>
    <action name="loadCandidateRegistrationForm" class="loadCandidateFromAction"
        method="loadCandidateRegistrationForm">
        <result name="success" type="tiles">registerCandidate</result>
    </action>

错误条件请求转发到“loadCandidateRegistrationForm”但我没有在页面上看到错误。我在jsp中包含了标签

StrutsConfig.xml

            <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <constant name="struts.objectFactory" value="spring" />
        <constant name="struts.devMode" value="false" />

        <constant name="struts.action.extension" value="action" />

        <constant name="struts.custom.i18n.resources" value="global" />

        <package name="org" namespace="/"
            extends="struts-default,json-default">

            <result-types>
                <result-type name="tiles"
                    class="org.apache.struts2.views.tiles.TilesResult" />
            </result-types>

            <global-results>
                <result name="welcome" type="tiles">welcome</result>
            </global-results>

        </package>

        <package name="org.unsecureActions" extends="org">
            <!--
                This package contains such a actions which doesn't need user logged
                in.
            -->

            <action name="welcome" method="forwardAction" class="baseAction">
                <result name="success" type="tiles">welcome</result>
            </action>

            <action name="logout" method="logoutCandidate" class="logoutAction">
                <result name="success" type="tiles">welcome</result>
            </action>

            <action name="loadAdvanceSearchForm" method="loadAdvanceSearch"
                class="advanceSearchAction">
                <result name="success" type="tiles">advanceSearch</result>
            </action>

            <!--Candidate workflow  actions -->
            <action name="registerCandidateStep1" class="candidateAction"
                method="registerCandidateStep1">
                <interceptor-ref name="store">
                    <param name="operationMode">STORE</param>
                </interceptor-ref>
                <interceptor-ref name="defaultStack" />

                <result name="success" type="tiles">registerCandidate</result>
                <result name="input" type="redirect">loadCandidateRegistrationForm.action</result>
            </action>

            <action name="registerCandidateStep2" class="candidateAction"
                method="registerCandidateStep2">
                <result name="success" type="tiles">registerCandidate</result>
                <result name="input" type="tiles">loadCandidateRegistrationForm</result>
            </action>
            <action name="registerCandidateStep3" class="candidateAction"
                method="registerCandidateStep3">
                <result type="chain">
                    <param name="actionName">loginCandidate</param>
                    <param name="namespace">/org.unsecureActions</param>
                </result>
                <result name="input" type="tiles">registerCandidate</result>
            </action>

            <action name="loadCandidateRegistrationForm" class="loadCandidateFromAction"
                method="loadCandidateRegistrationForm">
                <interceptor-ref name="store">
                    <param name="operationMode">RETRIEVE</param>
                </interceptor-ref>
                <result name="success" type="tiles">registerCandidate</result>
            </action>
            <!--Candidate workflow  actions -->

            <action name="loginCandidate" class="loginAction" method="loginCandidate">
                <result name="success" type="tiles">home</result>
                <result name="input" type="tiles">welcome</result>
            </action>

        </package>

        <package name="org.secureActions" extends="org">
            <!--
                This package contains such a actions which needs user must logged in
                before executing these.
            -->

            <interceptors>
                <!--
                    Following interceptor checks for is user logged in before executing
                    the action.
                -->
                <interceptor name="contextSecurityInterceptor"
                    class="org.kovid.matrimony.interceptor.ContextSecurityInterceptor">
                </interceptor>

                <!--
                    This stack is as like default stack provided ny Struts Only
                    difference is at the bottom of folowing stack where we included our
                    "contextSecurityInterceptor" interceptor.
                -->
                <interceptor-stack name="applicationStack">
                    <interceptor-ref name="exception" />
                    <interceptor-ref name="alias" />
                    <interceptor-ref name="servletConfig" />
                    <interceptor-ref name="prepare" />
                    <interceptor-ref name="i18n" />
                    <interceptor-ref name="chain" />
                    <interceptor-ref name="debugging" />
                    <interceptor-ref name="profiling" />
                    <interceptor-ref name="scopedModelDriven" />
                    <interceptor-ref name="modelDriven" />
                    <interceptor-ref name="fileUpload" />
                    <interceptor-ref name="checkbox" />
                    <interceptor-ref name="staticParams" />
                    <interceptor-ref name="actionMappingParams" />
                    <interceptor-ref name="params" />
                    <interceptor-ref name="conversionError" />
                    <interceptor-ref name="validation" />
                    <interceptor-ref name="workflow" />
                    <interceptor-ref name="contextSecurityInterceptor" />
                </interceptor-stack>
            </interceptors>

            <!--
                Setting default stack for interceptor taking care of this packageS.
            -->
            <default-interceptor-ref name="applicationStack" />

            <action name="home" method="forwardAction" class="baseAction">
                <result name="success" type="tiles">home</result>
            </action>

            <action name="loadAdvanceSearchForm" method="loadAdvanceSearch"
                class="advanceSearchAction">
                <result name="success" type="tiles">advanceSearch</result>
            </action>

            <action name="simpleSearch" method="simpleSearch" class="simpleSearchAction">
                <result name="success" type="tiles">search</result>
                <result name="input" type="tiles">home</result>
            </action>

            <action name="advanceSearch" method="advanceSearch" class="advanceSearchAction">
                <result name="success" type="tiles">search</result>
            </action>
            <action name="loadImage" method="loadImage" class="imageAction">
                <result name="imageData" type="stream">
                    <param name="contentType">${imageContentType}</param>
                    <param name="inputName">imageStream</param>
                    <param name="contentDisposition">filename="candidate.jpeg"</param>
                    <param name="bufferSize">${myBufferSize}</param>
                </result>
            </action>

        </package>

    </struts>

3 个答案:

答案 0 :(得分:3)

主动阻止动作链接,与验证拦截器的交互是其中一个原因。您可以通过将一些值(如验证消息)从一个动作显式映射到下一个动作来绕过它,但是......不要链接动作 - 几乎没有理由这样做。

答案 1 :(得分:2)

Dave所述,不鼓励使用Action Chaining

Action Chaining

  

请勿在家尝试此操作

     

通常,不建议使用Action Chaining。   首先探索其他选项,例如 Redirect After Post   技术

如果你有充分的理由使用Redirect After Post,请使用

答案 2 :(得分:0)

错误的生命周期持续当前的行动。如果您转发/重定向到其他操作,则错误将会丢失。

请改用session范围。将ArrayList放入session并附加您的错误/消息。

<强>动作/拦截器:

Map session         = ActionContext.getContext().getSession();
List<String> errors = session.get("errorMessages");

if(errors==null)
   session.put("errorMessages", errors=new ArrayList<String>() );

errors.add("Invalid Username/Password. Kindly retry");

<强> JSP:

<s:iterator var="msg" value="#session.errorMessages" >
     <p> ${msg} </p>
</s:iterator>
<s:set scope="session" var="errorMessages" value="%{null}" /><%--flush errors--%>