使用struts的同步令牌避免form的重复提交
提交到有令牌处理方法里
<a href="<%=path %>/bbs.do?method=getComment&cid=<%=comment.getId()%>" onclick="return GB_showCenter('编辑评论', this.href,250,550)">[编辑]</a>
FORM表单(必须用struts标签提交,不过表单里用原html表单也可以把值一块提交过去)
<div align="center">
<c:if test="${success=='ok'}" >
<script type="text/javascript">
alert("信息发表成功");
parent.parent.location.reload();
</script>
</c:if>
<html:form action="/bbs.do?method=updateComment">
<input type="hidden" name="id" value="${comment.id}"/>
<textarea cols="60" rows="7" name="content" id="content">${comment.content}</textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor( 'content' ) ;
oFCKeditor.BasePath = '<%=path%>/FCKeditor/' ;
oFCKeditor.ToolbarSet = 'yezhuTopic' ;
oFCKeditor.Width = '100%' ;
oFCKeditor.Height = '150' ;
oFCKeditor.Value = '' ;
oFCKeditor.ReplaceTextarea();
</script> <br/>
<html:submit value="提 交"/>
</html:form>
</div>
得到令牌
public ActionForward getComment(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException
{
this.saveToken(request);
request.setAttribute("comment", commentService.getCommentById(Integer.parseInt(request.getParameter("cid"))));
return mapping.findForward("updateComment");
}
public ActionForward updateComment(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
request.getSession().removeAttribute("msg");
request.getSession().removeAttribute("open");
if(this.isTokenValid(request)){
List listComment = commentService.update(request);
request.setAttribute("success", "ok");
request.getSession().setAttribute("listComment", listComment);
this.resetToken(request);
return mapping.findForward("updateComment");
}else{
return mapping.findForward("updateComment");
}
}
分享到:
相关推荐
struts2令牌解决页面重复提交问题,资源中包含一个实例代码
利用struts1的令牌来解决页面的重复提交问题
关于讲解struts令牌详细介绍 解决页面重复提交的好方式
struts2 令牌使用例子 直接导入使用
struts2中对表单重复提交的处理方法;包括处理两种典型的表单重复提交的思路和方法
专门为struts打造的,有效的防止重复提交,并且操作起来相当方便……
struts token机制解决表单重复提交
struts2令牌
运用struts2解决表单的重复提交问题
这里是Struts2 中放置表单重复提交的例子。
造成重复提交主要的两个原因: 1) 一是,服务器处理时间久。当用户在表单中填完信息,点击“提交”按钮后,由于服务器反应时间过长没能及时看到响应信息,或者出于其它目的,再次点击“提交”按钮,从而导致在...
Struts解决重复提交步骤也可以说是struts的令牌机制很有用的啊
防止重复提交的总要解决方案 相信对struts的学者有帮助 大家看看
Servlet、Struts、SpringMVC对于表单重复提交的解决方案
struts2防止表单重复提交,利用struts的拦截器tokenSession,轻轻松松解决表单重复提交的问题。 附件为源代码,后台延迟了3秒,可直接在web服务器下部署运行,输入用户名和密码后,多点几次提交按钮,然后看控制台...
在struts 中可以通过token 来解决重复提交的问题。
struts2防止表单重复提交--重定向