在Form域中Post大于100K的数据

当表单发送的数据量很大时,就会报错。查阅MSDN了解到,原因是微软对用Request.Form()可接收的最大数据有限制,IIS4中为80K字节,IIS5中为100K字节。
下面是微软提供的几个解决方法:

1、用Request.BinaryRead 代替 Request.Form方法 来解析表单数据;

2、使用文件上传方案,比如:Microsoft Posting Acceptor;

3、由于102399字节的限制是对每个表单元素的,所以在提交时,把表单元素内容大于102399的分隔成多个表单元素来提交。

下面为示例代码:(微软提醒:下面代码不一定完全适用特定的需要,不对使用这些代码产生的后果负责!)

1<form action="LargePost.asp" method="post" name="theForm" onsubmit="BreakItUp()">
2<textarea cols="100" name="BigTextArea" rows="3">A bunch of text...</textarea>
3<input type="submit" value="go"/>
4</form>
 1<script language="JavaScript">   
 2function BreakItUp()   
 3{   
 4//Set the limit for field size.   
 5//如果内容有中文的字符的话,可以设置为:51100   
 6var FormLimit = 102399   
 7//Get the value of the large input object.   
 8var TempVar = new String   
 9TempVar = document.theForm.BigTextArea.value   
10//If the length of the object is greater than the limit, break it   
11//into multiple objects.   
12if (TempVar.length > FormLimit)   
13{   
14document.theForm.BigTextArea.value = TempVar.substr(0, FormLimit)   
15TempVar = TempVar.substr(FormLimit)   
16while (TempVar.length > 0)   
17{   
18var objTEXTAREA = document.createElement("TEXTAREA")   
19objTEXTAREA.name = "BigTextArea"   
20objTEXTAREA.value = TempVar.substr(0, FormLimit)   
21document.theForm.appendChild(objTEXTAREA)   
22  
23TempVar = TempVar.substr(FormLimit)   
24}   
25}   
26}   
27</script>

接受数据页主要代码:

1   
2Dim BigTextArea   
3For I = 1 To Request.Form("BigTextArea").Count   
4BigTextArea = BigTextArea & Request.Form("BigTextArea")(I)   
5Next   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus