Use JScript to encode form data with UTF-8 (in desperation)

Source: Internet
Author: User

If you need to reprint it, please indicate the source and author. Thank you.
QQ: 221704
MSN: flyly@yeah.net
Email: zhangfl@sports.cn

Code:
<Scloud>
For (I = 0; I <_ INPUT. length; I ++ ){
If (_ INPUT [I]. type = "text "){
_ INPUT [I]. value = encodeuri (_ INPUT [I]. value );
}
}
For (I = 0; I <_ text. length; I ++ ){
_ Text [I]. value = encodeuri (_ text [I]. value );
}
Uploadform. Action = "uploadaction. Do ";
// Uploadform. Action = "testupload. jsp ";
Uploadbegin ();
Uploadform. Submit ();
</SCRIPT>
Here we first encode the data in the form. encodeurl this method to transfer out the encoding is UTF-8.

Then upload in the backgroundProgramIs decoding him.
If (item. isformfield ()){
Field. Add (urldecoder. Decode (item. getstring (), "UTF-8 "));
}

Why should I do this? Even very depressing. In an upload program, all the field data submitted in the form is garbled (???) when it is received in the background (???). I have tried filters and transcode using the new string method. (Other form submission programs will not see garbled characters. The codes from my pages to the database are gb2312, including filters ).
I think there are two possible scenarios: WebLogic does not know the encoding of the data submitted by me, another possibility is that the fileupload jar package internally encodes the requst data. but the garbled problem only occurs on the liunx platform.

In desperation, I had to encode UTF-8 submission. I did not expect the garbled problem to be solved. but I still don't know why. java cannot encode the data before submission, especially when the number of fields is uncertain. I had to use the functions provided by jscript for encoding. the above program is not ideal. because at the time of submission, the user will see that the field data is changed to UTF-8. it may make users feel unfriendly. the solution is to use the hidden box to submit data.

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.