解决Struts重复提交的问题

来源:百度文库 编辑:神马文学网 时间:2024/05/16 23:19:18
首先必须要通过一个Action再转向那个添加记录的页面,转向函数如下.
public ActionForward tokenTest(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
saveToken(request);//把一个token ID保存到Session,并在且要转到的页面
//的中添加一个的标答.
return mapping.findForward("add");
}
一个输出入页面如容如下:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>




tokentest.jsp


























用户名
地址:





页面的处理Action内容如下:
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
TokenTestForm tokenTestForm = (TokenTestForm) form;
if(!isTokenValid(request)){ //重复提交
request.setAttribute("error","不能得复提交!!!");
//saveToken(request); 重新生成tokenid,
return mapping.findForward("return");
}else{
resetToken(request);
}
//执行相关操作
System.out.println(tokenTestForm.getUsername()+"--"+tokenTestForm.getAddress());
return mapping.findForward("ok");
}
至此已完成,至于原理,就自己去查一些资料就完全明白了....