TokenHelper - 找不到映射到令牌名称struts.token的标记

时间:2013-09-15 08:34:07

标签: java multithreading struts2 token struts2-interceptors

如果我添加"execAndWait"拦截器,它会给我上面的错误:

TokenHelper - Could not find token mapped to token name struts.token

配置:

<action name="flightsearch" method="getFlightResult"
    class="com.test.FlightSearchAction">

    <interceptor-ref name="execAndWait">
        <param name="delay">500</param>
        <param name="delaySleepInterval">500</param>
    </interceptor-ref>
    <!--  <interceptor-ref name="token">
        <param name="excludeMethods">getFlightResult</param>
    </interceptor-ref> -->
    <result name="wait" type="tiles">flightwait</result>
    <result name="success" type="tiles">flightsearchresult</result>
</action>

<interceptors>
    <interceptor-stack name="tokenCheck">
        <interceptor-ref name="token" />
        <interceptor-ref name="defaultStack" />
        <interceptor-ref name="basicStackHibernate" />
    </interceptor-stack>

    <interceptor-stack name="loggingRequired">
        <interceptor-ref name="defaultStack" />
        <interceptor-ref name="basicStackHibernate" />
    </interceptor-stack>

</interceptors>

正如我所读到的,有人说这是一个警告,我们可以通过更改TokenHelper类来避免它。如果是这样怎么做?

1 个答案:

答案 0 :(得分:0)

仅当ActionContext包含参数token时,才会显示此警告。在execAndWait拦截器之前删除此参数。

ActionContext.getContext().getParameters().remove("token");

BTW,execAndWait拦截器应该在completeStack之后开始。例如

<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="completeStack"/>
    <interceptor-ref name="execAndWait"/>
    <result name="wait">wait.jsp</result>
    <result name="success">success.jsp</result>
</action>