struts 防止重复提交表单

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
    "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>


    <constant name="struts.devMode" value="true"></constant>
    <package name="test" namespace="/" extends="struts-default">
       
    <action name="input" class="com.bjsxt.action.InputAction">
            <result>/input.jsp</result>
           
           
        </action>

        <action name="user" class="com.bjsxt.action.UserAction">
            <result>/addOK.jsp</result>
           
           
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <interceptor-ref name="token"></interceptor-ref><!--  该重复提交拦截器一定要在defaultStack拦截器外边 -->
            <result name="invalid.token">/error.jsp</result><!--  重复提交会跳转到该页面 -->
        </action>

    </package>


</struts>

 

 

防止重复提交要在表单里面添加标签:

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'test.jsp' starting page</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 action="user" method="post">
        name:<input name="name">
        age:<input name="age">
        <input type="submit" value="add">
        <s:token></s:token>
    </form><br>
  </body>
</html>

原文地址:https://www.cnblogs.com/flying607/p/3473321.html