There are many articles in this regard on the Internet, which have been resolved according to the above, but I modified the MySQL configuration file my. ini. I feel that it is not very good at deployment.
Here is another solution (mysql-4.1.11). Earlier MySQL versions do not seem to have any problem with Chinese (mysql-4.0.17 ).
1. Add a filter to set character set encoding to UTF-8.
Modify web. xml:
<Filter>
<Filter-Name> setcharacterencoding </filter-Name>
<Filter-class> hxz. Filter. setencodingfilter </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> UTF-8 </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-Name> setcharacterencoding </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
Create a filter:
Package hxz. filter;
Import java. Io. ioexception;
Import javax. servlet .*;
Public class setencodingfilter implements filter {
// Default character encoding
String defaultencoding = "UTF-8 ";
Public void Init (filterconfig config) throws servletexception {
String encoding = config. getinitparameter ("encoding ");
If (encoding! = NULL ){
Defaultencoding = encoding;
}
}
Public void dofilter (servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception {
Request. setcharacterencoding (defaultencoding );
Chain. dofilter (request, response );
}
Public void destroy (){
Defaultencoding = NULL;
}
}
2. Modify the hibernate configuration file:
<Property name = "url">
<Value> JDBC: mysql: // localhost: 3306/test? Useunicode = true & amp; characterencoding = UTF-8 </value>
</Property>
Note the following: useunicode = true & amp; characterencoding = UTF-8, in XML & to change to; amp;
3. When creating a table in the new MySQL version, you can select a character set to set it to UTF-8.
In JSP or servlet, change character set to UTF-8.
4. trying...