1

我一直试图让 tokenSession 拦截器工作(Struts 2.0.14),但总是收到警告:

2013-03-13 08:32:09,395 [17] DEBUG Intercepting invocation to check for valid transaction token. | org.apache.struts2.interceptor.TokenSessionStoreInterceptor.doIntercept(128)
2013-03-13 08:32:09,395 [17] WARN  Could not find token name in params. | org.apache.struts2.util.TokenHelper.getTokenName(124)
2013-03-13 08:32:09,396 [17] DEBUG no token name found -> Invalid token  | org.apache.struts2.util.TokenHelper.validToken(154)
2013-03-13 08:32:09,397 [17] WARN  Could not find token name in params. | org.apache.struts2.util.TokenHelper.getTokenName(124)
2013-03-13 08:32:09,397 [17] WARN  Could not find token mapped to token name null | org.apache.struts2.util.TokenHelper.getToken(105)
2013-03-13 08:32:09,398 [17] DEBUG Forwarding to location /WEB-INF/view/support/TokenError.jsp | org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(113)

struts.xml 具有以下拦截器配置:

            <package name="survey" extends="struts-default">
        <result-types>
            <result-type name="csv"
                     class="webapp.CsvResultType"/>
            </result-types>

        <interceptors>
            <interceptor name="log"
                class="struts.LoggingInterceptor"/>
            <interceptor name="formAuthentication"
                class="security.FormAuthenticationInterceptor"/>
            <interceptor-stack name="default">
                <interceptor-ref name="log"/>
                <interceptor-ref name="servletConfig"/>
                <interceptor-ref name="formAuthentication"/>
                <!--interceptor-ref name="chain"/>-->
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="params"/>
            </interceptor-stack>
            <interceptor-stack name="defaultTokenStack">
                <interceptor-ref name="tokenSession"/>
                <interceptor-ref name="default"/>
            </interceptor-stack>

        </interceptors>

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

        <!--  -->

        <global-results>
             <result name="blank">/WEB-INF/view/support/Blank.jsp</result>
             <result name="error">/WEB-INF/view/support/Error.jsp</result>
             <result name="insufficientPrivileges">/WEB-INF/view/support/InsufficientPrivileges.jsp</result>
             <!--result name="file" type="file"></result-->
        </global-results>

    </package>

使用动作定义:

<package name="respondent" namespace="/respondent" extends="survey">
    <action name="*" class="controller.respondent.{1}Action">
        <interceptor-ref name="defaultTokenStack"/>
        <result name="list">/WEB-INF/view/respondent/{1}List.jsp</result>
        <result name="edit">/WEB-INF/view/respondent/{1}Edit.jsp</result>
        <result name="view">/WEB-INF/view/respondent/{1}View.jsp</result>
        <result name="success">/WEB-INF/view/respondent/{1}.jsp</result>
        <result name="invalid.token">/WEB-INF/view/support/TokenError.jsp</result>
    </action>
</package>

该 jsp 具有令牌标记:

<s:form action="FunctionSummary.action" method="post">
<s:token/>

    <table class="buttons">
        <tr>
            <s:if test="surveyStarted">
                <td><s:submit value="Resume Survey"/></td>
            </s:if>
            <s:else>
                <td><s:submit value="Start Survey"/></td>
            </s:else>

        </tr>
    </table>

</s:form>

对该页面的任何访问都会导致重定向到 invalid.token 结果和上述警告。

我已经验证,如果没有配置拦截器,页面源确实有令牌,但我无法让 sessionToken 拦截器看到它。

非常感激任何的帮助...

谢谢

4

1 回答 1

1

尝试将您的<s:token/>标签放入您的<table>标签中。我遇到了和你一样的问题。在我放入<s:token/>标签后<table>问题就解决了。

<s:form action="" id = "" theme="simple" method = "post">
<table id = "" border="1" width="200">
    <s:token/>  <!-- In the table tag -->

</table>
</s:form>
于 2013-06-05T15:26:53.763 回答