Request garbled GET request garbled: Reason: request parameter with URL address, URL address when to parse? Tomcat received a request to encode the URL (iso8859-1) solution: Configure the 8080 port on Tomcat plus uriencoding= "Utf-8";
<uriencoding= "Utf-8" connectiontimeout= "20000" Port = "8080" protocol= "http/1.1" redirectport= "8443"/>
Post request garbled: Reason: The request parameter is the decoder with the request body is the first time to obtain the parameter filter can be used to solve garbled request.setcharacterencoding ("utf-8") response garbled Response.setcontenttype ("Text/html;charset=utf-8") 1, Tomcat one installation, get started to server.xml in the 8080 add uriencoding= "Utf-8" 2, Put a filter on the project to get him to solve all the post garbled; 3, the SPRINGMVC comes with a garbled solution of the filter project in Web. config:
<!--The filter for character encoding must be placed at the front - <Filter> <Filter-name>Characterencodingfilter</Filter-name> <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class> <!--Configure encoding to tell us the encoding format specified - <Init-param> <Param-name>Encoding</Param-name> <Param-value>Utf-8</Param-value> </Init-param> <!--Resolve response garbled - <Init-param> <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> <!--the filter that supports rest - <Filter> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Filter-class>Org.springframework.web.filter.HiddenHttpMethodFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
Configuration inside the configuration of encoding and forceencoding look at Characterencodingfilter source, through Request.setcharacterencoding (this.encoding) and Response.setcharacterencoding (this.encoding) to troubleshoot post requests and response garbled questions:
Public classCharacterencodingfilterextendsOnceperrequestfilter {PrivateString encoding; Private BooleanForceencoding =false; Public voidsetencoding (String encoding) { This. Encoding =encoding; } Public voidSetforceencoding (Booleanforceencoding) { This. forceencoding =forceencoding; } @Overrideprotected voiddofilterinternal (httpservletrequest request, httpservletresponse response, Filterchain Filterchain) throwsservletexception, IOException {//encoding is UTF-8 .//forceencoding bit True if( This. Encoding! =NULL&& ( This. forceencoding | | request.getcharacterencoding () = =NULL) {request.setcharacterencoding ( This. Encoding); if( This. forceencoding) {response.setcharacterencoding ( This. Encoding); }} filterchain.dofilter (request, response); }}
Spring garbled problem solution