防止页面表单重复提交,JSP页面加入 <s:token/> 以及Struts的相关配置详解

jsp页面提交表单后,当刷新或者点击浏览器的后退按钮,刚才的表单会被重复提交一次,这不是我们期望的结果,为了防止页面表单重复提交,可以再JSP表单中加人<s:token/>标签,然后对Struts进行相关的配置即可。

在jsp界面加入token标签,首先要引入taglib  如下

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
	
<%@ taglib prefix="s" uri="/struts-tags" %>	

然后再form表单中加入token标签,如下:

<s:token></s:token>
       <input name="modify" type="submit" 


最后在struts.xml中配置一下,那么刷新就会跳到reformerror界面。
 <action name="user_*" class="userAction" method="{1}" >
        	<interceptor-ref name="defaultStack"></interceptor-ref>
 		<interceptor-ref name="token"></interceptor-ref>
    		<result name="invalid.token">/reformerror.jsp</result>


  • 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、付费专栏及课程。

余额充值