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

Source: Internet
Author: User

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 decode the object in the background upload program.
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.

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.