Today, I found that the project had a Chinese garbled problem !? Remember to configure the page encoding and filter. How can this problem be solved?
 
 
 
The code displayed on the page is as follows:
 
 
 <% @ Page Language = "Java" Import = "Java. util. *, pojo. *" pageencoding = "UTF-8" %>
 
 
 
The filter is also normal:
 
 
 
Because Ajax is also taken into account, it is a little different from the general filter, but the red part is indeed executed.
 
 
Public class encoding implements filter {private string charset; private string ajaxpostcontenttype; public static final string ajax_post_content_type_default = "application/X-WWW-form-urlencoded"; Public void destroy () {// todo auto-generated method stub} public void dofilter (servletrequest arg0, servletresponse arg1, filterchain arg2) throws ioexception, servletexception {// todo auto-generated met Hod stubhttpservletrequest request = (httpservletrequest) arg0; string requestsrc = request. getquerystring (); If (requestsrc! = NULL ){ Arg0.setcharacterencoding ("UTF-8"); arg1.setcharacterencoding ("UTF-8 "); Arg0.getparameter ("");} else {arg0.setcharacterencoding (charset); arg1.setcharacterencoding ("text/html; charset =" + charset);} arg2.dofilter (arg0, arg1 );} public void Init (filterconfig arg0) throws servletexception {// todo auto-generated method stubcharset = arg0.getinitparameter ("charset"); Signature = arg0.getinitparameter ("ajaxcontent "); if (ajaxpostcontenttype = NULL) {ajaxpostcontenttype = ajax_post_content_type_default ;}}} 
 
The configuration in Web. XML is as follows:
 
 
 <Filter> <filter-Name> encode </filter-Name> <filter-class> filter. encoding </filter-class> <init-param> <param-Name> charset </param-Name> <param-value> utf8 </param-value> </init- param> </filter> <filter-mapping> <filter-Name> encode </filter-Name> <URL-pattern>/* </url-pattern> </filter- mapping>
 
 
 
It seems that everything has been done. What is the problem? After some tests, the original problems were:
 
 
<Form ID = "trheaderform" name = "trheaderform" Action = "lagp. Do">
 
 
 
I checked it carefully and did not specify the submission method. Therefore, the get method is used by default! Changed:
 
 
 <Form ID = "trheaderform" name = "trheaderform" Action = "lagp. Do" method = "Post">
 
 
 
Test OK!
 
 
 
Summary:
 
 
 
1. Ensure that the JSP page code is UTF-8
 
 
 
2. Configured filter, forcibly encoded as UTF-8
 
 
 
3. Set form submission method to post