Javascript Chinese garbled characters in ie, and iejs Chinese garbled characters

Source: Internet
Author: User

Javascript Chinese garbled characters in ie, and iejs Chinese garbled characters


First common situation
Generally, as long as the jsp and js file encoding formats are consistent, Chinese garbled characters can be solved.
UTF-8 encoding has always been used, including pageEncoding of jsp pages.
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %>

If there is still a garbled problem, you need to consider what the web application server is. I encountered a situation where Chinese characters are garbled in the development environment and no Chinese characters are garbled when deployed to the testing machine, the biggest difference found through repeated tests is that

In the development environment, jetty is used to test tomcat.

In this direction, du Niang finally found the same victim,

Jetty's Chinese problems have never been well implemented by Tomcat, so Chinese garbled characters often occur.

Some experiences of the predecessors are verified, and some differences are found. When comparing Jetty and Tomcat parameters, the Response is found to be inconsistent.

Tomcat Response:
Content-Type application/javascript

Jetty's Response:
Content-Type application/x-javascript; charset = GB2312

This is the Validation result of my monitoring js file (ie)


The final solution is to add a filter in web. xml.
<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>


In this way, the response is UTF-8, And the garbled problem is finally solved.

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.