避免重复提交

action :
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.TestTokenForm;

/**
* MyEclipse Struts Creation date: 08-29-2008
*
* XDoclet definition:
*
* @struts.action path="/testToken" name="testTokenForm"
*                input="/form/testToken.jsp" scope="request" validate="true"
* @struts.action-forward name="sucess" path="/MyJsp.jsp"
*/

public class TestTokenAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestTokenForm testTokenForm = (TestTokenForm) form;// TODO
// Auto-generated
// method stub\
boolean blug = this.isTokenValid(request);
if(blug){
this.resetToken(request);
System.out.println("I love Ora");
}

return mapping.findForward("index");
}
}
pre:/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.PreForm;

/**
* MyEclipse Struts
* Creation date: 08-29-2008
*
* XDoclet definition:
* @struts.action path="/pre" name="preForm" input="/form/pre.jsp" scope="request" validate="true"
* @struts.action-forward name="MyJsp" path="/MyJsp.jsp"
*/
public class PreAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
PreForm preForm = (PreForm) form;// TODO Auto-generated method stub
this.saveToken(request);

return mapping.findForward("MyJsp");

}
}






jsp页面源代码;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-CN">
  <head>
    <base href="http://localhost:8081/Token/MyJsp.jsp">
   
    <title>MyJsp.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
 
  <body>
   <form name="testTokenForm" method="post" action="/Token/testToken.do"><div><input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="e52f13b4a3e49bdf52cce503388eaa05"></div>
   name:<input type="text" name="name"/>
   sex:<input type="text" name="sex"/>
   age:<input type="text" name="age"/>
   <input type ="submit" name ="ss" value="提交">
   </form>
  </body>
</html>

你可能感兴趣的:(apache,jsp,struts,MyEclipse,servlet)