`
wurushuang
  • 浏览: 38813 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用struts的同步令牌避免form的重复提交

阅读更多
使用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");
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics