(四)检查表单是否重复提交
在正式处理用户提交的表单之前,应该在dictionary对象中检查它的fid是否已经登记。下面的checkfid()函数用来完成这个工作,如已经登记,它返回false,否则返回true:
function checkfid()
dim strfid
initializefid
strfid = request("fid")
checkfid = not session("fidlist").exists(strfid)
end function
二、如何使用
有两个地方要用到上述函数,即表单生成时与结果处理时。假设上述四个子程序已经放入包含文件forms.inc中,下面的代码根据fid值来决定生成表单还是处理表单结果,它所描述的处理过程适合于大多数asp应用:
< %option explicit%>
< !--#include file="forms.inc"-->
< html>
< head>
< title>表单提交测试< /title>
< /head
< body>
< %
if request("fid") = "" then
generateform
else
processform
end if
%>
< /body>
< /html>
generateform负责生成表单,表单中应该含有一个隐藏的fid,如:
< %
sub generateform()
%>
< form action="< %=request.servervariables("path_info")%>"
method=get>
< input type=hidden name=fid value="< %=generatefid()%>">
< input type=text name="param1" value="">
< input type=submit value="ok">
< /form>
< %
end sub
%>
processform负责处理通过表单提交的内容,但在处理之前应该先调用checkfid()检查当前表单是否已经提交,代码类如:
< %
sub processform()
if checkfid() then
response.write "你输入的内容是" & request.querystring("param1")
registerfid
else
response.write "此表单只能提交一次!"
end if
end sub
%>
三、限制与改进措施
上面我们介绍了在当前会话期间限制同一表单被多次提交的一种方法。在实际应用中可能需要从多方面加以改进,例如:
⑴ 在登记表单id之前检查用户输入数据的合法性,使得数据不合法时用户可以按“后退”按钮返回,在修正后再次提交同一表单。
⑵ 这种对表单提交的限制最多只能在当前会话期间有效。如果要求这种限制能够跨越多个会话,那么就要用到cookeis或数据库来保存相关数据了。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器