struts2 使用标签防止表单重复提交

struts2 使用标签防止表单重复提交_第1张图片


第一步:index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'index.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">   
  </head>
  
  <body>
	  <s:form action="itcast" namespace="/test" method="post">
	  	姓名:<s:textfield name="name"/>
	  	<s:token></s:token><!--第一步   加入标签 -->
	  	<input type="submit" value="发送"/>
	  </s:form>
  </body>
</html>
第二步:strut.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<!-- 默认的视图主题 -->
	<constant name="struts.ui.theme" value="simple" />

	<package name="itcast" extends="struts-default">
		<action name="itcast" class="cn.itcsst.action.PersonAction">
			<!-- 第二步 加入以下拦截器 -->
			<interceptor-ref name="defaultStack" />
			<interceptor-ref name="token" />
			<result name="invalid.token">/index.jsp</result>
			<!-- 第二步结束   重复提交转向登陆界面 -->
			<result>/WEB-INF/page/message.jsp</result>
		</action>
	</package>
</struts>
大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑

你可能感兴趣的:(struts2,表单重复提交)