EXT form Submit garbled problem solve after __ garbled problem

Source: Internet
Author: User

This time to do the project encountered a thorny problem: I use ext time to put the Chinese in the URL inside, submitted to the Java server end with

Request.getparameter ("XM")

Immediately out of garbled. The server I use is tomcat, using

New String (Request.getparameter ("XM"). GetBytes ("Iso-8859-1"), "Utf-8")
It's OK. This is why. The reason is that ext submitted the URL with Utf-8 encoding, but after Tomcat was used to encode the iso-8859-1, so in the Java server to first use the Iso-8859-1 string parsing into a byte, No matter what encoding only the byte stream is the only constant, and credible, and then will parse out the byte stream, and then use the Utf-8 code display.
But the statement waits until it is put on WebSphere and then there is garbled. The reason is that URLs are not iso-8859-1 encoded through WebSphere, which is one of the different points between WebSphere and Tomcat.
so I changed the sentence to
New String (Request.getparameter ("XM"). GetBytes ("GBK"), "Utf-8")
Chinese display, but encountered odd words in the last word is always missing or garbled.
So I also adopted the Ext form, using post submission, or garbled.
finally consulted some people who have experience in this field, are said to utf-8 the project is good, so you can not transfer code, directly with
Request.getparameter ("XM")
It's OK, both on Tomcat and WebSphere. So I began to modify the project:
1, first of all the pages, with Notepad to open
<% request.setcharacterencoding ("Utf-8");%>
<% @ Page ContentType = "Text/html;charset=utf-8"%>



and Save as Utf-8 format
2, all used Js,css, are opened in Notepad and saved as Utf-8 format

3, Java server-side code typically outputs response set to
Response.setcontenttype ("text/html; Charset=utf-8 ");
4, if there is web.xml inside the use of filters, remember to set into Utf-8
5, when debugging the page open HttpWatch (this is a very useful debugging tools, monitoring the data flow of the Web page), to observe where there is not charset= "utf-8", Correct the
Such a change, garbled disappeared, do not have to turn the code, direct access, put where all good.
summarize the experience:
1, if there are Chinese places do not put in the URL, it is best to make a form to submit
2, the project adopts utf-8 unification

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.