Extjs Ajax garbled problem Solving solution _extjs

Source: Internet
Author: User
In one page browsing process, the client initiates the browsing request to a URL, the service side resolves to this request, but in the character encoding parsing aspect, first he examines the character encoding setting in the page, namely <meta http-equiv= "Content-type" Content = "text/html; Charset=utf-8 "/&gt, so that the display of the character encoding in the page is UTF-8, the server will output the page in UTF-8 encoding, and if the page does not display a declaration, there is a default character encoding in the server, such as GB2312, For files that are not declared, he will use the default encoding output, this time, if the page output is UTF-8, this will appear garbled.
In ext, in the process of submitting data, the EXT framework is all UTF-8 encoding, and the data submitted through JSON is UTF-8 encoding, so all files are required to be UTF-8 encoded.
Ways to solve garbled characters
The following items must first be done in the usual coding process:
(1) Java background file to join Response.setcontenttype ("text/html");
Response.setcharacterencoding ("Utf-8");
(2) Display the declaration character encoding in the file, <meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "/>
(3) for the submission of garbled, in EXT can modify the request header Content-type settings, the specific method is: Ext.lib.Ajax.defaultPostHeader + = "; Charset=utf-8";
Finally, the problem may also appear in the file save format. When you save the code file, if the development environment is not saved by default UTF-8 format, then there will be problems! So there is a need for the development environment.
Configuration of the development environment
If you use Notepad to write a save code file (. js), this will cause problems, mainly because the default encoding format for Notepad in the Windows system is ANSI, which is basically different from the format encoded in the current page so that the encoding format is incorrect. The solution is to open the Xx.js file and save it as, and select the Utf-8 encoding format at the save type.
Of course, the mainstream is still using myeclipse, so say myeclipse where to configure.
Preferences->general->content Types Select text to edit the following default encoding for Utf-8 and then update.
Preferences->general->content types->editors->text editors->spelling Encoding Select default (UTF-8)
Preferences->general->content types->workspace under Text File Encoding Select Other:utf-8
Finally, if there are garbled, use
System.out.print (Request.getcharacterencoding ());
System.out.print (Response.getcharacterencoding ());
See if the request or response encoding is not utf-8
If not, use the filter in Web.xml to solve.
Such as
<filter>
<description>no</description>
<display-name>EncodingFilter</display-name>
<filter-name>EncodingFilter</filter-name>
<filter-class>
Com.hope.filters.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
or set
<globalization responseencoding= "Utf-8" fileencoding= "Utf-8" requestencoding= "Utf-8"/>
Good luck!
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.