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”结果。

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