![](/img/trans.png)
[英]TokenHelper - Could not find token mapped to token name struts.token
[英]struts2 token error struts.token and struts.token.name
當我使用以下代碼時,我正在測試令牌的不同場景,並遇到此問題:
<action name="sincronizar" class="action.SincronizarAction">
<interceptor-ref name="token"/>
<interceptor-ref name="mystack"/>
<result name="success" type="tiles">d_sincronizar</result>
<result name="input" type="tiles">d_sincronizar</result>
<result name="invalid.token" type="tiles">d_sincronizar</result>
</action>
在控制台中出現此錯誤:
WARNING: Error setting expression 'struts.token' with value '[Ljava.lang.String;@3584de'
ognl.OgnlException: target is null for setProperty(null, "token",
[Ljava.lang.String;@3584de)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2312)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
現在我用“ basicStack”重拍:
<action name="sincronizar" class="action.SincronizarAction">
<interceptor-ref name="token"/>
<interceptor-ref name="basicStack"/>
<result name="success" type="tiles">d_sincronizar</result>
<result name="input" type="tiles">d_sincronizar</result>
<result name="invalid.token" type="tiles">d_sincronizar</result>
</action>
沒問題。 但我需要使用我的堆棧。 另外,當我使用相同的攔截器制作新堆棧時,也會遇到相同的問題。 示例:lowStack相同的basicStack http://struts.apache.org/development/2.x/docs/interceptors.html
<interceptor-stack name="lowStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
</interceptor-stack>
<action name="sincronizar" class="action.SincronizarAction">
<interceptor-ref name="token"/>
<interceptor-ref name="lowStack"/>
<result name="success" type="tiles">d_sincronizar</result>
<result name="input" type="tiles">d_sincronizar</result>
<result name="invalid.token" type="tiles">d_sincronizar</result>
</action>
我也有同樣的問題。
發生這種情況是因為您缺少params
攔截器的excludeParams
參數。 它看起來應該像這樣:
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
</interceptor-ref>
看一下定義了basicStack
攔截器的struts-default.xml
。
老問題了,但是我遇到了這個問題,excludeParams沒有用。 在測試我的應用程序時,仍然需要在表單上進行兩次提交。
解決該問題的方法是對消息進行更深入的思考。 Struts嘗試設置該值,這不是在表單上表示,而是在動作控制器java對象中表示。 因此,只需為String令牌添加一個set / get即可。
在動作類中添加:
String token;
public void setToken(String token) { this.token = token; }
public String getToken() { return token; }
很確定這就是問題所在。 使用排除參數只會隱藏它,從而阻止攔截器嘗試訪問代碼庫中缺少的方法。
這里也有一些很好的信息:
我在他的教程中發表了一些評論以擴展內容,但是等待主持人批准,然后才能在此處看到它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.