Struts2学习笔记(8-3)----表单重复提交

本文介绍了如何在Struts框架中防止表单的重复提交,包括使用<s:token>标签、配置拦截器、设置错误显示页面及自定义错误信息等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
<div class="item-body"><div class="item-content" id="main-content">[size=large; font-family: 黑体;]1.加入<s:token>标签[/size]
在<s:form ...></s:form>中加入
<s:token></s:token>

<s:token name="hello"></s:token>
将会生成
<input type="hidden" name="struts.token.name" value="hello">
<input type="hidden" name="hello" value="dbfipua0ifvgs9..." />

[size=large; font-family: 黑体;]2.加入拦截器
[/size]在struts.xml中的action中加入token拦截器
<interceptor-ref name="[size=small; font-family: georgia;][b]token[/b][/size]"></interceptor>
<interceptor-ref name="defaultstack"></interceptor>

[size=large; font-family: 黑体;]3.配置 结果页面[/size]
在struts.xml的action中加入result,name为invalid.token
<result name="[size=small; font-family: georgia;][b]invalid.token[/b][/size]">/registor.jsp</result>

[size=large; font-family: 黑体;]4.显示出错信息[/size]
<s:actionerror cssstyle="color:red"/>

[size=large; font-family: 黑体;]5.修改默认的出错信息[/size]
默认信息在struts-messages.properties中
struts.messages.invalid.token="the form ..."
在自定义的message_zh_cn.properties中替换
struts.messages.invalid.token=请不要重复提交表单
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值