struts2 <s:token/>标签防止表单重复提交

  对于采用token防止表单重复提交的原理我就不用多说了,大家也应该都知道,在这我只介绍在struts2中如何利用标签实现防止表单的重复提交。   

  首先在表单中加入标签 ,会生成一个隐藏域用于存储系统自动随机生成的token值。然后在action中启用TokenInterceptor,即在struts.xml中加入下面类似代码。 

<action name="register" class="UserAction" method="register">
	<result>register_success.jsp</result>
	<result name="input">register.jsp</result>
	<result name="invalid.token">register.jsp</result>
	<interceptor-ref name="token"></interceptor-ref>
	<interceptor-ref name="defaultStack"></interceptor-ref>
</action>		

  其中<result name="invalid.token">register.jsp</result>”是在发生表单重复提交时,返回给用户提示信息的显示页面,同时还需在显示页面中加入 ;“<interceptor-ref name="token"></interceptor-ref>”是启用TokenInterceptor 如果表单重复提交,会提示The form has already been processed or no token was supplied, please try again。修改国际化文件struts.messages.invalid.token 的键值,提供自己定制的错误信息。比如:struts.messages.invalid.token= 您已经提交了表单,请不要重复提交。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释下这段代码:private static void createPicture(int format, InputStream pictureData, int width, int height, XWPFParagraph paragraph) { String blipId = null; try { blipId = paragraph.getDocument().addPictureData(pictureData, format); } catch (InvalidFormatException e) { e.printStackTrace(); } int id = paragraph.getDocument().getAllPictures().size() - 1; final int EMU = 9525; width *= EMU; height *= EMU; CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline(); String picXml = "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:nvPicPr>" + " <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + " <a:stretch>" + " <a:fillRect/>" + " </a:stretch>" + " </pic:blipFill>" + " <pic:spPr>" + " <a:xfrm>" + " <a:off x=\"0\" y=\"0\"/>" + " <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + " </a:xfrm>" + " <a:prstGeom prst=\"rect\">" + " <a:avLst/>" + " </a:prstGeom>" + " </pic:spPr>" + " </pic:pic>" + " </a:graphicData>" + "</a:graphic>"; inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; try { xmlToken = XmlToken.Factory.parse(picXml); } catch (XmlException xe) { xe.printStackTrace(); } inline.set(xmlToken); inline.setDistT(0); inline.setDistB(0); inline.setDistL(0); inline.setDistR(0); CTPositiveSize2D extent = inline.addNewExtent(); extent.setCx(width); extent.setCy(height); CTNonVisualDrawingProps docPr = inline.addNewDocPr(); docPr.setId(id); docPr.setName("img" + id); docPr.setDescr("word" + id); }
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值