Implementation of large-capacity data submission method by ASP

Source: Internet
Author: User
Tags string split domain
Previously encountered a problem in the work, when the form sent a large amount of data, it will be an error. Check out MSDN to learn that Microsoft is limited to 100K bytes for the maximum data that can be received with Request.Form ().

Microsoft recommends using Request.BinaryRead () to read form data, but because this method reads binary data, it needs to parse the read out bytes, generating a meaningful string (a program on MSDN is written like this, However, it does not take into account the need for special analysis of escape characters such as punctuation. If this approach is barely available for a pure English system, for the Chinese system has great trouble, because the Chinese character is expressed in two bytes, and read the binary data itself can not be judged in English or Chinese characters (otherwise it is not binary data, but the string of ^). In this way, we must understand the coding rules of Chinese characters in order to analyze. Finally, even if the algorithm can analyze all of these, we think of a MB-level mega-string analysis by Byte, how efficient? So, blocked!

But there is always a way. At first I thought it was the sum of the form's data cannot exceed 100KB, which was later found to be a restriction on each field within the form. The solution to the problem is that, for a domain that needs to send large data, the data is split into a number of smaller than the limit before submitting the form, placed in several hidden fields, and emptied of the original field, then formally submits the form. Server-side or with Request.Form () read the data of each hidden field, and then in order to put them together on the line. The main code is as follows:

Note: You need to specify a div within the HTML code in the form to dynamically insert the hidden field into it.

= = = Client Sample Code = = =

The following are the referenced contents:

<script language=javascript>
file://data splits and places them in the corresponding hidden field, triggering in the onsubmit event of the form
function Fnprehandle ()
{
var icount; How many fields file://split into
var strdata; file://Raw Data
var imaxchars = 50000;//The maximum number of characters in a field is limited to 50K, taking into account that Chinese characters are double-byte
var Ibottleneck = 2000000;//If the article is more than 2M words, you need to prompt the user
var strhtml;//raw Data
Strdata = frmtest.bigfield.value;//If the article is too long, you need to remind the user
if (Strdata.length > Ibottleneck)
{
If confirm ("the article you are publishing is too long, it is recommended that you split it into several sections and publish separately.") \ NAND If you insist on submitting, note that it will take a long time to commit successfully. \ n \ ndo you insist on submitting? ") = = False)
return false;
}icount = parseint (strdata.length/imaxchars) + 1;//hdncount record How many subdomains the original data field is split into
strhtml = "<input type=hidden name=hdncount value=" + icount + ">";//Generate HTML code for each child domain
for (var i = 1; I <= icount; i++)
{
strHTML = strhtml + "\ n" + "<input type=hidden Name=hdnbigfield" + i + ">";
}//HTML code for dynamically inserting hidden fields within div (divhidden) in form
Document.all.divHidden.innerHTML = strhtml;//Assign values to each subdomain
for (var i = 1; I <= icount; i++)
{
frmtest.elements["Hdnbigfield" + I].value = strdata.substring ((i-1) * Imaxchars, I * imaxchars);
}//Original Data field empty
FrmTest.BigField.value = "";
}
</SCRIPT>

= = = = = Server-side Sample Code = =

The following are the referenced contents:

<%
Dim strdata
Dim Intfieldcount
Dim Iintfieldcount = Request.Form ("Hdncount") for I=1 to Intfieldcount
strdata = strdata & Request.Form ("Hdnbigfield" & i)
Nextresponse.write strdata
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.