日期:2014-05-20  浏览次数:20671 次

使用Struts的Token机制,控制form重复提交
小弟用struts   做了个系统,但是出现过form重复提交,现在知道Struts的Token机制能解决这个问题,但是不知道具体怎么用,请问有哪个大哥能教教我

------解决方案--------------------
不知道那个机制
我的方法是这样的

首先在form里实现reset()方法,把所有属性=null;
然后在action里,用完form后,做form.reset();

OK
------解决方案--------------------
在Action类里面的execute里面
写上
this.saveToken(request);

在提交的方法中

if (!isTokenValid(request, true)) {
//
}
进行判断是否重复提交
------解决方案--------------------
this.saveToken(request);
后,表单里面会自动产生这样的隐藏输入表单域
<input type= "hidden " name= "org.apache.struts.taglib.html.TOKEN " value= "6602b5d7c9e511229ad845823b2becd2 ">
------解决方案--------------------
提交页面前一个action saveToken(request);


提交页面 <input type= "hidden " name= "org.apache.struts.taglib.html.TOKEN "
value= " <%=session.getAttribute( "org.apache.struts.action.TOKEN ")%> "/>


处理提交的action if(isTokenValid(request,true)){
//commonDataBean.executeUpdate(sql);//处理执行sql语句代码
resetToken(request);
}else{
saveToken(request);
}
------解决方案--------------------
认真看了我写的内容的意思了吗?

<input type= "hidden " name= "org.apache.struts.taglib.html.TOKEN "
value= " <%=session.getAttribute( "org.apache.struts.action.TOKEN ")%> "/>
把这句原封不动的加到页面的from中。。。