struts2的開發(的使用)

在struts2中使用<s:token>可以防止表單的重複提交;

用法如下:

1,在表單中添加<s:token>標籤:

<s:form action="helloworld_other" method="post" namespace="/test">
        <s:textfield name="person.name"/><s:token/><s:submit/>
 </s:form>

2,在struts.xml中配置攔截器:

第二步:
<action name="helloworld_*" class="com.xasxt.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”結果。

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