struts2防止表單重複提交



1、struts.xml文件action中配置重複提交表單攔截器

		<action name="login" class="loginAction">
			<result name="input">/login.jsp</result>
			<result name="success">/index.jsp</result>
			<!-- 重複提交表單時,跳轉路徑 -->
			<result name="invalid.token">/token.jsp</result>
			<!-- 重複提交表單攔截器 -->	
			<interceptor-ref name="token"></interceptor-ref>
			<!-- struts2默認攔截器 -->
			<interceptor-ref name="defaultStack"></interceptor-ref>
		</action>



2、前臺代碼添加在form表單裏添加:<s:token></s:token>

		<s:form name="form1" action="login" method="POST">
			<s:token></s:token>
			<s:textfield name="user.userId" label="用戶名" value=""
				style="width:200px;height:30px; line-height:20px;padding:5px;"></s:textfield>
			<s:password name="user.password" label="密 碼" value=""
				style="width:200px;height:30px; line-height:20px;padding:5px;"></s:password>
			<s:submit value="提交" style="width:80px;height:25px;"></s:submit>
			<s:reset value="重置" style="width:80px;height:25px;"></s:reset>
		</s:form>


發佈了53 篇原創文章 · 獲贊 2 · 訪問量 48萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章