首页 > 代码库 > struts1与struts2的防止表单重复提交

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

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>