In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what to do about Chinese garbled codes in ajax sent by springmvc. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
I am using sping-web-3.2.2,jar
Method 1:
Add produces = "text/html;charset=UTF-8" to @ RequestMapping
}
Method 2:
Because the character set is set to ISO-8859-1 by default in StringHttpMessageConverter
So get the source code, modify it to UTF-8 and package it to spring-web-3.2.2.jar
Public class StringHttpMessageConverter extends AbstractHttpMessageConverter {public static final Charset DEFAULT_CHARSET = Charset.forName ("UTF-8");. }
Method 3:
Modify the parameters of org.springframework.http.MediaType 's constructor and add the configuration to applicationContext-mvc.xml
Public MediaType (String type, String subtype, Charset charset) {super (type, subtype, charset);}
Xml code
Method 4
The org.springframework.http.converter.StringHttpMessageConverter class is a class that handles requests or corresponding strings, and the default character set is ISO-8859-1, so garbled code occurs when Chinese characters are returned in the json.
There is a List supportedMediaTypes attribute in the parent class of StringHttpMessageConverter, which is used to store MediaType types that StringHttpMessageConverter supports that require special handling. If the MediaType type to be processed is not in the supportedMediaTypes list, the default character set is used.
As a solution, simply add the following code to the configuration file:
Application/json;charset=UTF-8
If you need to deal with other MediaType types, you can add other value tags to the list tag
This is the end of the article on "what to do about Chinese garbled codes in springmvc ajax". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.