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.