struts2標籤 攔截器 (1)

<s:token />標籤防止重複提交,用法如下:
第一步:在表單中加入<s:token />
<s:form action="helloworld_other" method="post" namespace="/test">
<s:textfield name="person.name"/><s:token/><s:submit/>
</s:form>
第二步:
<action name="helloworld_*" class=“com.ambow.action.HelloWorldAction" method="{1}">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="token" />
<result name="invalid.token">/WEB-INF/page/message.jsp</result>
<result>/WEB-INF/page/result.jsp</result>
</action>
以上配置加入了token攔截器和invalid.token結果,因爲token攔截器在會話的token與請求的token不一致時,將會直接返回invalid.token結果。
 
debug狀態,控制檯出現下面信息,是因爲Action中並沒有struts.tokenstruts.token.name屬性,我們不用關心這個錯誤:
嚴重: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'struts.token' on 'class xxx: Error setting expression 'struts.token' with value '[Ljava.lang.String;@39f16f'
嚴重: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'struts.token.name'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章