11.Struts2的防止表单的重复提交

要进行重复提交验证的表单内要加上<s:token />的struts的标签。

这个标签的作用就是在页面生成时会生一个标识符,struts2会自动将此标识符放在session中,当此表单提交时,当表单成功提交,即返回的为success时,struts2会自动将session中的标签符清空,将第二次再提交时struts会检查此值是否为空,若为空则返回invalid.token值,此时struts2会找到此action对应的result,然后返回相应的页面。所以要进行重复提交检查的action应当配置

name=invalid.token的result项。并且,进行重复提交验证的拦截器必须要配置,因为struts2默认并不对此进行配置。

   <!--

使用struts2的action很简单,也只继承一个ActionSupport就可以了,完全可以实现struts1.x中的

Action ,MappingDispatcherAction,DispatcherAction要实现的功能。

添加一个method属性则请求此action时会调用对应名称的业务处理方法。

若不加,则有两种情况

1.执行默认的execute方法。(此时请求的的path为register.action)

2.执行指定的方法,这个指定要在请求时指定.(此时请求的path为register.action!callMethodName.action)

比较奇怪,不过好用。

 -->

<action name="register" class="edu.yzu.action.UserAction" >

<!-- result 的name属性可以不写,不写的话表示为success -->

<result name="invalid.token" type="redirect">/index.jsp</result>

<result>/result.jsp</result>

<result name="input">/index.jsp</result>

<result name="login">/login.jsp</result>

<!--

为这个action指定拦截器,若不指定刚会使用此包的默认拦截器

若指定一个拦截器,则此包的默认拦截器则不会被用于拦截些action

所以若还要使用默认拦截器时必须显示指出,如下:

 -->

<interceptor-ref name="token"></interceptor-ref>

<interceptor-ref name="thirdinterceptor"></interceptor-ref>

<interceptor-ref name="mystack"></interceptor-ref>

<interceptor-ref name="thirdinterceptor"></interceptor-ref>

<interceptor-ref name="thirdinterceptor"></interceptor-ref>

</action>

posted @ 2010-05-03 17:06  沉兮  阅读(730)  评论(0编辑  收藏  举报