We all know that in the JSP code is the most annoying things, some garbled out of the inexplicable, to the development of a great deal of trouble, but to make a garbled filter on everything is resolved, after the configuration, you do not need to be in the page to do transcoding and so on.
First, write a filter class, as follows: package filter; import java.io.ioexception; import javax.servlet.filter; import javax.servlet.filterchain; import javax.servlet.filterconfig; import javax.servlet.servletexception; import javax.servlet.servletrequest; import javax.servlet.servletresponse; import javax.servlet.http.httpservletrequest; public class pageencodingfilter implements filter{ private string encoding = "UTF-8"; protected FilterConfig filterconfig; public void init (Filterconfig filterconfig) throws ServletException { this.filterconfig = filterconfig; //the default encoding for this filter is UTF-8, but you can also set your own code in Web.xml configuration file if (Filterconfig.getinitparameter ("encoding") != null) encoding = Filterconfig.getinitparameter ("encoding"); } public void dofilter (servletrequest srequset, servletresponse sresponse, filterchain filterchain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) srequset;      &NBsp; request.setcharacterencoding (encoding); filterchain.dofilter (srequset, sresponse); } public void destroy () { this.encoding = null; } }
Then, in the Web.xml configuration, as follows:
<filter> <filter-name>encoding </filter-name> <filter-class>filter. pageencodingfilter</filter-class> < init-param> < param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Here, everything is OK, you can rest assured that the code, and will not worry about the occurrence of garbled.