Another new project is about to begin. It may still need to use the SSH framework, so I decided to repeat the use of SSH. In fact, the use of the framework is still very simple, we should focus more on learning the implementation principles of the framework.
The garbled problem occurs when struts transmits Chinese characters. In my opinion, the most concise solution is to do the following:
1. Set pageencoding to GBK or gb18030;
2. Add a filter to Web. xml;
< Filter >
< Filter-name > Gbkencoding </ Filter-name >
< Filter-class > Com. sshnews. Filter. gbkencodingfilter </ Filter-class >
</ Filter >
< Filter-Mapping >
< Filter-name > Gbkencoding </ Filter-name >
< URL-Pattern > /* </ URL-Pattern >
</ Filter-Mapping >
3. compile the Code : package COM. sshnews. filter;
Import JAVA. io. ioexception;
Import javax. servlet. * ;
Import javax. servlet. HTTP. * ;
Public class gbkencodingfilter implements filter {
private filterconfig config = null ;
Public VoidInit (filterconfig arg0)ThrowsServletexception {
This. Config=Arg0;
}
Public Void Dofilter (servletrequest req, servletresponse res, filterchain FC) Throws Ioexception, servletexception {
If ( This . Config = Null ){
Return ;
}
// System. Out. println ("filter running ");
Req. setcharacterencoding ( " GBK " );
FC. dofilter (req, Res );
}
Public VoidDestroy (){
}
}
OK. I personally think this is the most concise method. If the database is still garbled, refer to the following Article
JAVA to write MySQL Chinese garbled solutions