質問

I am encountering a weird error using struts2's addActionError method.

My code in Action Class is:

this.addActionError(e.getMessage()); 
forward = ERROR;

STRUTS.xml:

 <action name="test" class="test">
    <result name="success">/struts/success.jsp</result>
    <result name="error">/struts/error.jsp</result>
    <interceptor-ref name="MyInterceptorStack" />
</action>

where MyInterceptorStack is:

<interceptor-stack name="MyInterceptorStack">
    <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="params">
            <param name="excludeParams">dojo\..*</param>
    </interceptor-ref>
    <interceptor-ref name="conversionError" />
    <interceptor-ref name="DeltaInterceptor" />
    <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>

My JSP:

<div><s:actionerror/></div>

Message should be: enter image description here

But the result duplicates as follows:

enter image description here

役に立ちましたか?

解決

Do you have struts.xwork.chaining.copyErrors = true set in your struts.properties or struts.xml ?

It would override normal behaviour, giving chain interceptor the ability to preserve action error messages through chains... who knows how it would act with no chains (it's possible that it copies them the same, assuming you use chain interceptor only with chained results, when this var is set to true)...

just a try.

EDIT: can you print out a line from java when you add the message ?

this.addActionError(e.getMessage()); 
System.out.println("Setting action error");
forward = ERROR;

just to check that the action is not called twice for some reason...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top