struts的token-个人制作

【第一步】

使用token必须使用struts的标签库:

Form表单如下:

  <body>

   <s:actionerror/>

  <s:form action="tokenTest">

  <s:token></s:token>

    <input value="11992352364573591235" name="key"/>

    <s:textfield name="username" label="username"></s:textfield>

    <s:submit value="submit"></s:submit>

  </s:form>

  </body>

【第二步】

注册token的资源文件,token_zh.properties,该文件放在src下面,下划线前面的部分为前缀:


内容如下:

struts.messages.invalid.token=\

u8BF7\u4E0D\u8981\u91CD\u590D\u63D0\u4EA4


【第三步】

在struts.xml文件中加载token:

<?xml version="1.0"encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//ApacheSoftware Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

<constant name="struts.ui.theme"value="xhtml"></constant>

   <constant name="struts.custom.i18n.resources" value="token"></constant>

   <package name="default" extends="struts-default">

      <action name="tokenTest"class="com.aaa.action.TestTokenAction">

         <interceptor-ref name="token"></interceptor-ref>

         <interceptor-ref name="defaultStack"></interceptor-ref>

         <result name="index">/index.jsp</result>

         <result name="invalid.token">/reg.jsp</result>

      </action>

   </package>

</struts>


【最后】

         在对提交的页面进行刷新时,提交的信息就会显示在  <s:actionerror/>

的位置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值