Utf-8 encoding of form data with JScript (reluctantly)
Source: Internet
Author: User
Code:
<sccript>
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>
This is where the data in the form is encoded. Encodeurl This method turns out the encoding is UTF-8.
And decoding him in the background upload program.
if (Item.isformfield ()) {
Field.add (Urldecoder.decode (item.getstring (), "UTF-8"));
}
Why do I have to do this? I am also very depressed. In an uploaded program. Table dropdowns submitted field data are all garbled when received in the background (???). Filters and transcoding with new string I've tried it all. (No garbled problems occur with other form submission programs.) My pages to the database are all GB2312 encoded, including filters.
I think there are two possible scenarios: one is WebLogic I don't know what to do with the data I submit, and one possibility is to encode the requst data inside the jar FileUpload. But the garbled problem only appears on the Liunx platform.
In desperation I had to utf-8 the data before submitting it. I didn't think the garbled problem should be solved. But I still don't know what causes this. Java cannot encode data before it is submitted. Especially in the case where the number of field is indeterminate. You have to encode it with functions provided by JScript. The above procedure is not ideal. Because the user will see field data become utf-8 at the time of submission. The solution is to use the hidden box to submit the data. .
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.