Document directory
- List the solutions that can be found again:
- 1. When connecting to the database
- 2. Set the MySQL Character Set
- Show variables like 'character _ SET _ % ';
- Set all the displayed character_set _ ** to utf8, that is, set character_set_serve = 'utf8'
- Show variables like '% collation % ';
- Set all displayed items to the following: Set collation_server = 'utf8 _ general_ci'
- 3. Modify the MySQL configuration file my. ini.
- Default-character-set = utf8
- 4. Create a filter class
- Package com. broadengate. CRM. filter;
- Import java. Io. ioexception;
- Public class characterencodingfilter implements filter {
- }
- 5. modify the configuration file server. XML in Tomcat.
- Change
-
- 6. Configure spring filter in Web. xml
- <Filter>
- <Filter-Name> char </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>
- </Filter>
- <Filter-mapping>
- <Filter-Name> char </filter-Name>
- <URL-pattern>/* </url-pattern>
- </Filter-mapping>
List the solutions that can be found again: 1. When connecting to the database, JDBC. properties: JDBC: mysql: // localhost: 3306/myproject? Useunicode = true & characterencoding = utf8
Applicationcontext. xml: JDBC: mysql: // localhost: 3306/myproject? Useunicode = true & amp; characterencoding = utf8
2. Set the MySQL Character Set
show variables like'character_set_%';
Set all the displayed character_set _ ** to utf8, that is, set character_set_serve = 'utf8'
show variables like '%collation%';
Set all displayed items to the following: Set collation_server = 'utf8 _ general_ci'
3. Modify MySQL configuration file my. inidefault-character-set = utf8
4. Create a filtering class package com. broadengate. CRM. 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; public class characterencodingfilter implements filter {public void destroy (){
} Public void dofilter (servletrequest request, servletresponse response,
Filterchain chain) throws ioexception, servletexception {
Request. setcharacterencoding ("UTF-8 ");
Chain. dofilter (request, response );
} Public void Init (filterconfig arg0) throws servletexception {
} Add web. xml configuration
<Filter>
<Filter-Name> encodefilter </filter-Name>
<Filter-class> com. broadengate. CRM. Filter. characterencodingfilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> encodefilter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
5. modify the configuration file server. XML in Tomcat <connector Port = "8080" protocol = "HTTP/1.1"
Connectiontimeout = "20000"
Change redirectport = "8443"/> to <connector Port = "8080" protocol = "HTTP/1.1"
Connectiontimeout = "20000"
Redirectport = "8443" uriencoding = "UTF-8"/> 6. xml configuration spring filter <filter> <filter-Name> char </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> </filter> <filter-mapping> <filter-Name> char </filter-Name> <URL-pattern>/* </url-pattern> </filter- mapping>