1、insertData.jsp:
<%@ page language="java" pageEncoding="GBK"%>
< import="org.apache.struts.util.TokenProcessor"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>insertData.jsp</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>
<%
TokenProcessor.getInstance().saveToken(request);
%>
<body>
<form action="saveData.jsp" method="post">
<input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="<%=session.getAttribute("org.apache.struts.action.TOKEN")%>" />
<input type="text" name="username" />
<input type="text" name="password" />
<input type="submit" value="Submit" />
</form>
</body>
</html:html>
2、saveData.jsp:
< import="org.apache.struts.util.TokenProcessor"%><%
// HttpSession session1 = request.getSession();
//System.out.println(session1.getAttribute("org.apache.struts.action.TOKEN"));
//System.out.println(session.getAttribute("org.apache.struts.action.TOKEN"));
Thread.sleep(3000);
String username = null;
String password = null;
TokenProcessor procesToken = org.apache.struts.util.TokenProcessor.getInstance();
if(procesToken.isTokenValid(request,true)) {
username = request.getParameter("username");
password = request.getParameter("password");
System.out.println("*********username:"+username);
System.out.println("*********password:"+password);
org.apache.struts.util.TokenProcessor.getInstance().resetToken(request);
} else {
org.apache.struts.util.TokenProcessor.getInstance().saveToken(request);
response.sendRedirect("http://localhost:8080/WebProject/token/saveData.jsp");
}
%>