Spring Chinese garbled problem

Source: Internet
Author: User

First: Code

@RequestMapping (value = "/query/{keyword}", method = Requestmethod.get, produces = "text/html;charset=utf-8")
public string query (@PathVariable string keyword) {

}

Second: in Tomcat Server.xml
<connector connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443" URIEncoding= "UTF-8"/ >

Note: If you use Eclipse to start Tomcat, you need to add the connector in Server.xml below workspace uriencoding= "UTF-8"

Reference: http://www.cnblogs.com/zhonghan/p/3339150.html

=======================================

    <Filter>       <Filter-name>Characterencodingfilter</Filter-name>        <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class>        <Init-param>            <Param-name>Encoding</Param-name>            <Param-value>GBK</Param-value>        </Init-param>        <Init-param>  <!--forcing a conversion -  <Param-name>Forceencoding</Param-name>  <Param-value>True</Param-value>      </Init-param>   </Filter>    <filter-mapping>       <Filter-name>Characterencodingfilter</Filter-name>       <Url-pattern>/*</Url-pattern>   </filter-mapping>  

Invalid if no coercion conversion parameter is added

Reference

http://blog.csdn.net/lufeng20/article/details/7311959

===================================

Today, when building the SPRING3 MVC framework, I found that there was a garbled (the All-evil ISO code AH), remembered before resolving post commit chaos

Package com.mocha.servlet;

Import Javax.servlet.ServletConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.springframework.web.servlet.DispatcherServlet;

public class Encodingdispatcherservlet extends Dispatcherservlet {
Private String encoding;

public void init (ServletConfig config) throws servletexception {
encoding = Config.getinitparameter ("encoding");
Super.init (config);
}

protected void Doservice (HttpServletRequest request, httpservletresponse response) throws Exception {
request.setcharacterencoding (encoding);
Super.doservice (request, response);
}
}

Then change the configuration in Web. XML to:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>com.mocha.servlet.EncodingDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

 ok, garbled disappear, now summed up the problem of garbled, get method garbled solution is generally the Conf directory in Tomcat server.xml file to add

<connector port= "8080" maxhttpheadersize= "8192"
maxthreads= "minsparethreads=" maxsparethreads= "75"
Enablelookups= "false" redirectport= "8443" acceptcount= "100"
connectiontimeout= "20000" disableuploadtimeout= "true" uriencoding= "UTF-8"/>

The Post method solves garbled characters by setting up a filter or servlet that specifically handles the encoding conversion.

http://blog.csdn.net/nivana999/article/details/18557179

Spring Chinese garbled problem

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.