此文章实现了防止struts页面重复提的功能。
第一步:struts.xml
<!-- 与spring集成时http://www.ganxisky.cn/,绿软指定由spring负责action对象的创建-->
<constant name="struts.objectFactory" value="spring"/>
<!-- 默认视图主题 -->
<constant name="struts.ui.theme" value="simple" />
<!-- 打印更多的详细信息 发布的时候改为false-->
<constant name="struts.devMode" value="true" />
<!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true" />
<package name="test" extends="struts-default" namespace="/testToken">
<action name="loginAction" class="cn.dunkai.action.support.demo.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
<result name="invalid.token">/error.jsp</result>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="token" />
</action>
</package>
第二步:testToken.
Action中没有任何变化,和没有添令牌时一样,不需要修改<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>struts2 test token</title> </head> <body> <s:form action="loginAction!testToken.action" namespace="/testToken"> <s:textfield name="message" label="请输入您的信息"/> <s:token name="token"/> <s:submit value="确定" /> </s:form> </body> </html>