struts2中表单重复提交的问题

看了网上说的有关struts2不重复刷新有很多,基本上都是在同一个页面中可以,那么我说下在一个页面中有一个按钮当点击后,到另一个页面。这个页面有许多列表记录,点击保存后再一次跳转到上一次页面中。那么在当前页面点击右键刷新,问题就在这了。

以前的
html:
<s:form action="topic" method="post">
<s:token name="topic.name"/>
</s:form>


struts.xml:
<action name="topic_*" method="{1}" class="topicAction">
<result name="success">/topic/manage_topic.jsp</result>
<result name="invalid.token" type="dispatcher">/common/noBack.jsp</result>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="token">
<param name="includeMethods">addTopicElement</param>
</interceptor-ref>
<interceptor-ref name="token">
<param name="excludeMethods">default</param>
</interceptor-ref>

</action>

注意:
【1】:
<s:token>标签创建一个新的令牌值,并用你所指定的令牌名把令牌保存到session中。而这个令牌值是随即产生的经过加密的字符序列,不会重复。

其次需要为action配置TokenInterceptor或者TokenSessionStoreInterceptor拦截器。这两个拦截器都已经在struts-default.xml中定义,但没有包含在defaultStack拦截器栈中。

【2】:
<interceptor-ref name="token"/>和<interceptor-ref name="defaultStack"/>是两个拦截器的配置,目的是为了接收页面传入

的token令牌及参数,<result name="invalid.token">/common/noBack.jsp</</result>指当发现重复提交时,需要流转到的页面.
【3】:
excludeMethods指定要排除的方法,includeMehtods是要拦截的方法。



如果是用javascript来提交的话,看下边----
function selectA() {

var url = "relation_addRelationshipTopic.do?relation.rnId=<%=rn != null ? rn.getId().longValue() : -1%>&relation.selectRn="+selectRn+"&fresh=" + Math.random()+"";
var token = "struts.token.name=relation.token";
var token2 = "relation.token=";
token2 += document.getElementsByName("relation.token")[0].value;
url += "&" + token + "&";
url += token2;
location = url;
}

注:
<s:token name="relation.token"/>
它回自动的生成两个hidden,一个是struts.token.name,一个是reletion.token.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值