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

  • 相关阅读:
    Centos安装步骤
    Charles抓包工具的使用
    Charles抓包问题
    关于Windows系统下端口被占用的问题和task命令
    Selenium3+python自动化016-Selenium Grid
    Selenium3+python自动化016-多线程
    JDBC使用案例
    JDBC基础和使用
    文件下载案例
    ServletContext
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100566.html
Copyright © 2020-2023  润新知