yunye 的 JavaBlog

@see codemouse

统计

留言簿(1)

阅读排行榜

评论排行榜

在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.如果重复提交表单就会弹出错误提示对话框

posted on 2008-03-22 01:39 yunye 阅读(207) 评论(0)  编辑  收藏 所属分类: jsp


只有注册用户登录后才能发表评论。


网站导航: