Jetty Chinese garbled Problem Solution

Source: Internet
Author: User

Jetty's Chinese problems have never been well implemented by Tomcat, so Chinese garbled characters often occur. Jetty-maven-plugin is used in the work, and jetty and maven are used in combination to deploy and release projects. However, Chinese characters are always garbled during requests in the browser, however, it is normal to deploy the project to Tomcat. Because it has been busy, and Tomcat is used in the online environment, it will not be solved without affecting the work. Today, I felt uncomfortable looking at the strange garbled characters, so I took some time to check related problems. Google Baidu found many problems in this regard for a while, but they are not consistent with my problems. Some solutions, such as Jetty version change, won't work. The developer tool of chrome browser is called up (press the F12 key in chrome), and the relevant Request and Response parameters are viewed in detail. It is found that the Response content of the program is also correct, garbled characters occur during browser parsing. And compare Jetty and Tomcat parameters found that Tomcat Response: Content-Type: text/html; charset = Response: Content-Type: in text/html, there must be a problem here. In addition to some information found on Google, I thought of resetting ContentType with Response. The relevant code is as follows: @ RequestMapping (value = "getDealGeoSearchForMobile ") @ ResponseBodypublicbyte [] getDealGeoSearch (HttpServletResponse response) {response. setContentType ("text/html; charset = UTF-8"); return "Chinese";} then tested, garbled Code finally disappeared. Everything works. In addition. in xml, you also need to configure the relevant EncodingFilter to make the encoding into a UTF-8, the configuration is as follows: <filter> <filter-name> encodingFilter </filter-name> <filter-class> org. springframework. web. filter. characterEncodingFilter </filter-class> <init-param> <param-name> encoding </param-name> <param-value> UTF-8 </param-value> </init- param> <init-param> <param-name> forceEncoding </param-name> <param-value> true </param-value> </init-param> </filter> <filter-mapping> <filter- Name> encodingFilter </filter-name> <url-pattern>/* </url-pattern> </filter-mapping>.

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.