Summary of Web request garbled problem

Source: Internet
Author: User

Issue 1:SPRINGMVC returns values (including Chinese characters) to the page via @responsebody, garbled

Solution:

After the springmvc3.2 can be declared note drive (do not know is not so translated) when the control of the code conversion, the result is so solved, too handsome!

<Mvc:annotation-driven>      <mvc:message-converters>          <!--default stringhttpmessageconverter, solve encoding problem -          <Beanclass= "Org.springframework.http.converter.StringHttpMessageConverter">              <Constructor-argvalue= "UTF-8" />              < Propertyname= "Writeacceptcharset"value= "false" />          </Bean>      </mvc:message-converters>  </Mvc:annotation-driven> 

Issue 2: (Note: This method only resolves the garbled post request)

JSP page Chinese input, to controller garbled, this time needs to be set to add a coded filter in the Web. xml file (filter) to unify the encoding to UTF-8, the code is as follows:

Web. XML configuration file:

<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>

It is important to note that it is best to place this code at the beginning of the Web. XML because the interception is in order and is easily intercepted if placed behind.

Problem 3:get Request garbled

Add the Server.xml file in the Tomcat server uriencoding= "UTF-8

Such as:

<connectiontimeout= "20000"  port= "8080"  protocol = "http/1.1" Redirectport = "8443"  uriencoding= "UTF-8"  />

Summary of Web request 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.