• java 服务器端验证重复提交


    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");
        }
    %>

  • 相关阅读:
    python列表切片
    python注释行与段落
    PCL安装与配置
    自动驾驶相关
    (转)ping命令
    (转)linux应用之test命令详细解析
    (转)shell解析命令行的过程以及eval命令
    (转)ssh-keygen 中文手册
    (转)stty 命令说明及使用讲解
    (转)CentOS下的trap命令
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100566.html
Copyright © 2020-2023  润新知