您的位置:首页 > 编程语言 > Java开发

struts1与struts2的防止表单重复提交

2014-08-08 14:10 399 查看
struts1的防止表单重复提交

一、方法:利用令牌来解决页面重复提交的问题

二、步骤

  2.1 Action中需要添加以下代码

    

public ActionForward entry(ActionMapping mapping, ActionForm form,
HttpServletRequestrequest, HttpServletResponse response)
throws Exception {
saveToken(request);
return mapping.findForward("showAll");
}
public ActionForward  update(ActionMapping mapping, ActionForm form,
HttpServletRequestrequest, HttpServletResponse response)
throws Exception {
if (isTokenValid(request, true)) {
UserForm actionForm=(UserForm)form;
.................
return mapping.findForward("success");
}else{
saveToken(request);
return mapping.findForward("error");
}

}


  2.2 jsp页面必须用struts1标签表单

 

<%@ taglib uri="http://struts.apache.org/tags-html"  prefix="html" %>
<html:form action="User" method="post">
'''''''''''''
</html:form>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: