a custom class (note the properties in which the configuration in Web. XML is based on this class)ImportOrg.springframework.web.filter.OncePerRequestFilter;ImportJavax.servlet.FilterChain;Importjavax.servlet.ServletException;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjava.io.IOException;Importjava.io.UnsupportedEncodingException;ImportJava.util.Iterator;/*** Filter-encoded format conversion*/ Public classEncodingconvertfilterextendsOnceperrequestfilter {/**original encoding format: corresponding settings in the Web. xml File*/ PrivateString fromencoding = "Iso-8859-1"; /**destination encoding format: corresponding settings in the Web. xml File*/ PrivateString toencoding = "UTF-8"; @SuppressWarnings ("Unchecked") @Overrideprotected voidDofilterinternal (HttpServletRequest request, httpservletresponse response, Filterchain Filterchain)throwsservletexception, IOException {if(Request.getmethod (). Equalsignorecase ("GET")) { for(Iterator<string[]> Iterator =Request.getparametermap (). values (). iterator (); Iterator.hasnext ();) {string[] parames=Iterator.next (); for(inti = 0; i < parames.length; i++) { Try{Parames[i]=NewString (Parames[i].getbytes (fromencoding), toencoding); } Catch(unsupportedencodingexception e) {e.printstacktrace (); }}}} filterchain.dofilter (request, response); } /*** Get the original encoding format *@returnOriginal encoding format*/ PublicString getfromencoding () {returnfromencoding; } /*** Set the original encoding format *@paramfromencoding * Original encoding format*/ Public voidsetfromencoding (String fromencoding) { This. fromencoding =fromencoding; } /*** Get target encoding format *@returnDestination encoding format*/ PublicString gettoencoding () {returntoencoding; } /*** Set Target encoding format *@paramtoencoding * Target encoding format*/ Public voidsettoencoding (String toencoding) { This. toencoding =toencoding; }} II, web. XML<!--Springmvc Self-setting filter post--><filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <!--where encoding is used to set the encoding format, forceencoding is used to set whether to ignore the request.getcharacterencoding () method, set to true to force overwrite the previous encoding format--& Lt;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><!--custom Filter GET requests if uriencoding= "is configured in the Server.xml file in Tomcat UTF-8 ", can not need-<filter> <filter-name>encodingConvertFilter</filter-name> <filter-class>home.xxx.filter.encodingconvertfilter</filter-class> <init-param> <param-name>fromEncoding</param-name> <param-value>iso-8859-1</p aram-value> </init-param> <init-param> <param-name>toEncoding</param-name> < Param-value>utf-8</param-value> </init-param> </filter><filter-mapping>
161912. Tool class: SPRING+SPRINGMVC custom code Conversion