码迷,mamicode.com
首页 > 其他好文 > 详细

struts2防止重复提交的办法

时间:2014-10-27 17:46:48      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   使用   java   for   sp   

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

  	<constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" /> 

    <package name="default" namespace="" extends="struts-default">
        <!-- 这里是拦截器的配置 -->
        <interceptors>
            <interceptor name="test" class="com.test.interceptor.TestInterceptor"></interceptor>  
            <!-- 用于仅拦截某些方法 -->
            <interceptor name="function" class="com.test.interceptor.FunctionInterceptor">
                <param name="includeMethods">add</param>
            </interceptor>  
             <interceptor-stack name="myStack">
                 <interceptor-ref name="test"/>
                 <interceptor-ref name="function"/>
                 <interceptor-ref name="token"/>
                 <interceptor-ref name="defaultStack"/>
             </interceptor-stack>
        </interceptors>
        
    	<!-- 正确和错误的分别跳转,input是在验证失败后会跳转的页面 -->
    	<action name="data" class="com.test.action.ValideAction">
    	    <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 -->
    	     <result name="success">/result.jsp</result>
    	    <result name="input">/login.jsp</result>
    	    <result name="invalid.token">/token_error.jsp</result><!-- 防止重复提交的办法 -->
    	</action>
    	
    	<action name="FunctionInterceptor" class="com.test.action.ValideAction" method="add">
    	    <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 -->
    	     <result name="success">/result.jsp</result>
    	    <result name="input">/login.jsp</result>
    	     <result name="invalid.token">/token_error.jsp</result>
    	</action>
    	<action name="dele" class="com.test.action.ValideAction" method="dele">
    	    <interceptor-ref name="myStack"></interceptor-ref> <!-- 使用拦截器的动作 -->
    	     <result name="success">/result.jsp</result>
    	    <result name="input">/login.jsp</result>
    	     <result name="invalid.token">/token_error.jsp</result>
    	</action>
    </package>
</struts>

上面是struts.xml中的代码,主要的代码是:

 <result name="invalid.token">/token_error.jsp</result>

这样一段。


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 这个地方是用来显示错误信息 -->
<s:fielderror/>
<form action="data.action" method="post">
用户名:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
-------------------联系方式----------------<br>
手机:<input type="text" name="contact.phone"><br>
地址:<input type="text" name="contact.address"><br>
邮箱:<input type="text" name="contact.email"><br>

<s:token></s:token><!-- 防止重复提交,要加上这一段话 -->
<input type="submit" name="ok"><br><br>


<a href="FunctionInterceptor.action">测试FunctionInterceptor的add</a><br><br>
<a href="dele.action">测试FunctionInterceptor的dele</a><br><br>
</form>
</body>
</html>

在JSP页面中,要加上这样一段话,<s:token></s:token><!-- 防止重复提交,要加上这一段话 -->

就可以防止重复提交了。

bubuko.com,布布扣

struts2防止重复提交的办法

标签:blog   http   io   os   ar   使用   java   for   sp   

原文地址:http://blog.csdn.net/itbuluoge/article/details/40508813

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!