转载 jsp 表单防止重复提交(简单版)
原文地址 http://wanchong958.iteye.com/blog/233791
// 页面代码start
<%
Random random = new Random();
//生成随机flag,
Integer flag=new Integer(random.nextInt());
session.setAttribute("flag",flag);
%>
//form代码
<input type=hidden name="flag" value="<%=flag%>">
//页面代码end
//处理表单代码 start
Integer flag =new Integer(Integer.parseInt(request.getParameter("flag")));
HttpSession session=request.getSession();
if (flag.equals(session.getAttribute("flag"))){
//在此调用dao
destroyFlag(session);
} else {
System.out.println("重复提交");
}
/**
* 销毁flag
* @param session
*/
public void destroyFlag(HttpSession session) {
session.removeAttribute("flag");
}