hibernate mysql_Hibernate+mysql 中文问题解决方案.

1. mysql安装时设置字符集utf-8, jdbc驱动3.0.15以上.

2. hibernate配置文件中,加上属性

true

UTF-8

3. web.xml设置Filter

=================================================

Set Web Application Character Encoding

filter-name>

cn.com.commnet.util.SetEncodeFilterfilter-class>

defaultencodingparam-name>

UTF-8param-value>

init-param>

filter>

Set Web Application Character Encoding

filter-name>

/*url-pattern>

filter-mapping>

=============================================

SetEncodeFilter.java

public class SetEncodeFilter implements Filter {

protected FilterConfig filterConfig = null;

protected String defaultEncoding = null;

/* (non-Javadoc)

* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)

*/

public void init(FilterConfig arg0) throws ServletException {

// TODO Auto-generated method stub

this.filterConfig = arg0;

this.defaultEncoding = filterConfig.getInitParameter("defaultencoding");

}

/* (non-Javadoc)

* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)

*/

public void doFilter(

ServletRequest request,

ServletResponse response,

FilterChain chain)

throws IOException, ServletException {

// TODO Auto-generated method stub

request.setCharacterEncoding(selectEncoding(request));

chain.doFilter(request, response);

}

public void destroy() {

this.defaultEncoding = null;

this.filterConfig = null;

}

protected String selectEncoding(ServletRequest request) {

return this.defaultEncoding;

}

}

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2009-07-15 09:01

浏览 695

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值