- 爱易网页
-
ASP教程
- 学习ASP之解决大字段在Form中Post出错的方法
日期:2010-09-10 浏览次数:21173 次
我们在使用很多新闻系统的时候,都会发现一个问题,尤其是使用 HtmlEdit 从WORD文档中直接拷贝文章(尤其里面有复杂表格和文字)的时候,提交会有一个错误发生。
"Request Object, ASP 0107 (0x80004005)"
很多编程人员都以为是 Access 数据库备注字段64kb限制的问题,开始 icech 也以为是,但是后来用了其他新闻系统的 SQL 版本,同样的问题发生了。因此我猜想,可能是浏览器的问题。但是 Form 表单使用的都是 Post 方式,应该和浏览器无关,那是什么原因呢?
程序出错提示总是在 Request.Form(“xxx”)的地方,因此我判断,可能是Request有大小的限制。然后就去MSDN上查找“ASP 0107 (0x80004005)”,果然是Request的问题。微软的原文是这样的。
PRB: Error "Request Object, ASP 0107 (0x80004005)" When You Post a Form
The information in this article applies t
Microsoft Active Server Pages
This article was previously published under Q273482
SYMPTOMS
When you post a large form field in Microsoft Internet Information Services 5.0, you may receive the following error message:
Error Type:
Request object, ASP 0107 (0x80004005)
The data being processed is over the allowed limit.
When you post a large form field in Microsoft Internet Information Server 4.0, you may receive the following error message:
Request object error 'ASP 0107 : 80004005'
Stack Overflow
/projectname/page.asp, line XX
The data being processed is over the allowed limit.
CAUSE
The size limit of each form field that is retrieved in the Request object is 102,399 bytes. The error occurs when you exceed this limit.
RESOLUTION
To resolve this problem, use one of the following methods:
Instead of reading form variable values with the Request.Form collection, use Request.BinaryRead (Request.TotalBytes), and parse the form values from the output of Request.BinaryRead.
Use a File Upload scheme, such as Microsoft Posting Acceptor.
Break the HTML form variables into multiple form variables before you submit the form. The 102,399 byte limit is for each form variable, so you can have multiple form variables of 102,399 characters or less. The following sample code illustrates this: WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
<FORM method=post action=LargePost.asp name=theForm >
<Textarea rows=3 cols=100 name=BigTextArea>A bunch of text...</Textarea>
<input type=submit value=go>
</form>
<SCRIPT Language=JavaScript>
function BreakItUp()
{
//Set the limit for field size.
var FormLimit = 102399
//Get the value of the large input object.
var TempVar = new String
TempVar = document.theForm.BigTextArea.value
//If the length of the object is greater than the limit, break it
//into multiple objects.
if (TempVar.length > FormLimit)
{
document.theForm.BigTextArea.value = TempVar.substr(0, FormLimit)
TempVar = TempVar.substr(FormLimit)
while (TempVar.length > 0)
{
var objTEXTAREA = document.createElement("TEXTAREA")
objTEXTAREA.name = "BigTextArea"
objTEXTAREA.value = TempVar.substr(0, FormLimit)
document.theForm.appendChild(objTEXTAREA)
TempVar = TempVar.substr(FormLimit)
}
}
}
</SCRIPT>
The receiving Active Server Page (ASP) page reconstructs the variable:
<%
Dim BigTextArea
For I = 1 To Request.Form("BigTextArea").Count
BigTextArea = BigTextArea & Request.Form("BigTextArea")(I)
Next
%>
100 K的限制?微软竟然来这一手!幸好他们自己给出了几个解决方案,看一下上文可以知道,微软提供了2种可行的方法:
第一种使用Request.BinaryRead (Request.TotalBytes),第二种使用分段上传的方式,基于少更改程序的原则,我们采用第二种方式。但是在使用的过程中,icech无意中发现,直接使用
For I = 1 To Request.Form("BigTextArea").Count