Hibernate+spring+struts+mysql乱码终极解决方案

(1)对mysql的my.ini配置文件的默认编码(好像是default-char-set)utf8

重启mysql服务。

(2)web.xml配置过滤器,这个应该很简单,copy就OK了

Xml代码

  SetWebApplicationCharacterEncoding  *.*.SetEncodeFilter  defaultencoding UTF-8   SetWebApplicationCharacterEncoding  /*   Set Web Application Character Encoding  *.*.SetEncodeFilter    defaultencoding  UTF-8    Set Web Application Character Encoding  /*

字符串过滤类

Java代码

importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;publicclassSetEncodeFilterimplementsFilter{  protectedFilterConfigfilterConfig=null; protectedStringdefaultEncoding=null;  publicvoidinit(FilterConfigarg0)throwsServletException{    this.filterConfig=arg0;    this.defaultEncoding=filterConfig.getInitParameter("defaultencoding");  }  publicvoiddoFilter(    ServletRequestrequest,    ServletResponseresponse,    FilterChainchain)    throwsIOException,ServletException{    request.setCharacterEncoding("UTF-8");    chain.doFilter(request,response);  }  publicvoiddestroy(){    this.defaultEncoding=null;    this.filterConfig=null;  }}

可以一个人,可以几个人,一起放松那劳累的心情或者劳累自己的身体,

Hibernate+spring+struts+mysql乱码终极解决方案

相关文章:

你感兴趣的文章:

标签云: