struts2 tokensession not setting request in Action excludedMethod

时间:2018-01-11 08:42:17

标签: struts2 token

I'm trying to avoid double-submit problems using tokenSession. My action methods are working fine without tokenSession technique.
I add <s:token/> in upsert_crypto_sources.jsp and tokenSession interceptor in struts.xml but I receive request as null in my action excludedMethod of list(). The list page doesn't need to avoid double submit problem but if I add <s:token/> in view_crypto_sources_list.jsp and remove list() from excludedMethod then I always receive result invalid.token.
My struts.xml is like:

<struts>
  <package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
    <action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
    <interceptor-ref name="tokenSession">
            <param name="excludeMethods">
                list, initInsert, load, delete
            </param>
        </interceptor-ref>
    <result name="list">/shared/km/view_crypto_sources_list.jsp</result>
    <result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
    <result name="update">/shared/km/upsert_crypto_sources.jsp</result>
    <result name="load">/shared/km/upsert_crypto_sources.jsp</result>
    <allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>   
</action>

My action implements ServletRequestAware interface therefore it gets the request member variable set using setServletRequest() method.

1 个答案:

答案 0 :(得分:0)

我添加了一个defaultStack拦截器,它运行正常:

<struts>
  <package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
    <action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
      <interceptor-ref name="defaultStack"></interceptor-ref>
      <interceptor-ref name="tokenSession">
            <param name="excludeMethods">
                list, initInsert, load, delete
            </param>
        </interceptor-ref>
    <result name="list">/shared/km/view_crypto_sources_list.jsp</result>
    <result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
    <result name="update">/shared/km/upsert_crypto_sources.jsp</result>
    <result name="load">/shared/km/upsert_crypto_sources.jsp</result>
    <allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>   
</action>