struts2 令牌 实现源代码 JSP

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Struts_token.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
         <!-- 防止表单重复提交,记得在form表单里填上<s:token></s:token>      -->
      <!-- action="token"、action="tokenSession" -->
      <s:form action="token.action" namespace="/test" method="post">
          姓名:<s:textfield name="name"/><s:token></s:token>
          <input type="submit" value="发送"/>
      </s:form>
  </body>
</html>
其实很简单实用,只要在表单中在form表单里填上<s:token></s:token>   就可以了,是不是很简单。原理就是它会自动生成一串二进制码。STRUTS会自动在提交的时候去做比对。


posted on 2013-12-02 14:01  王大王  阅读(143)  评论(0编辑  收藏  举报

导航