服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > J2EE > Servlet/Jsp > 查看文档

在jsp客户端限制表单重复提交

       在客户端限制表单重复提交有两种方法:
         第一种:在javascript脚本中设置一个标志变量,来区分表单是否已经提交。如果已经提交,则弹出对话框告诉用户“重复提交”。
        第二种:在单击提交按钮以后将提交按钮设置为disabled状态,这样用户就无法再提交按钮,客户端也就无法重复提交。
        采用第一种方法:

1.新建一个clienttest1.jsp文件,代码如下:


<%@ page language="java" contenttype="text/html; charset=gb2312"
    pageencoding="gb2312"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>客户端限制重复提交</title>
<script language="javascript"
    <!--定义重复提交标志变量 -->
    var repeatsubmitflag = false;
    <!-- 重复提交检查函数 -->
    function checksubmit()
    {
        if(repeatsubmitflag) <!-- 如果标志为true,则说明页面已经提交 -->
        {
            window.alert('禁止重复提交!');
            return false;
        }
        else
        {
            repeatsubmitflag = true;
            return true;
        }
    }
</script>
</head>
<body bcolor="#ffffff">
    <form name="form_client" action="http://www.dlmu.edu.cn" onsubmit="return checksubmit();">
        <input type="checkbox" name="check_1" checked=true/>大连海事大学
        <input type="submit" name="submitok"/>
    </form>
</body>
</html>


  2.如果重复提交表单就会弹出错误提示对话框

    采用第二种方法:
1.新建一个clienttest2.jsp文件,代码如下:

<%@ page language="java" contenttype="text/html; charset=gb2312"
    pageencoding="gb2312"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>客户端限制重复提交-2</title>
</head>
<body bgcolor="#ffffff">
    <form name="form_client" action="http://www.dlmu.edu.cn"
        onsubmit="window.document.form_client.submitok.disabled=true; return true;">
        <input type="checkbox" name="check_1" checked="true"/>大连海事大学
        <input type="submit" name="submitok"/>
    </form>
</body>
</html>

2.如果重复提交表单就会弹出错误提示对话框

扫描关注微信公众号