自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Hibernate+MySQL 中文問題的解決

數(shù)據(jù)庫 MySQL
今天我們主要向大家描述的是Hibernate+MySQL 中文問題的實際解決方法,如果你你對其相關內(nèi)容有所了解的話,會在你今后的學習中收獲很大。

以下的文章主要講述的是Hibernate+MySQL 中文問題的實際解決方法,即 MySQL數(shù)據(jù)庫安裝時我們設置的相關字符集為 utf-8, jdbc 驅(qū)動3.0.15 以上,以下的內(nèi)容就是對Hibernate+MySQL 中文問題的實際解決方案的介紹。

1、Hibernate+MySQL 中文問題解決方案:MySQL安裝時設置字符集utf-8, jdbc驅(qū)動3.0.15以上.

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

  1. <property name="connection.useUnicode">true</property>   
  2. <property name="connection.characterEncoding">UTF-8</property>  

3. web.xml設置Filter
 

  1. <filter>   
  2. <filter-name>   
  3. Set Web Application Character Encoding   
  4. </filter-name>   
  5. <filter-class>cn.com.commnet.util.SetEncodeFilter</filter-class>   
  6. <init-param>   
  7. <param-name>defaultencoding</param-name>   
  8. <param-value>UTF-8</param-value>   
  9. </init-param>   
  10. </filter>   
  11. <filter-mapping>   
  12. <filter-name>   
  13. Set Web Application Character Encoding   
  14. </filter-name>   
  15. <url-pattern>/*</url-pattern>   
  16. </filter-mapping>   
  17. SetEncodeFilter.java   
  18. public class SetEncodeFilter implements Filter {   
  19. protected FilterConfig filterConfig = null;   
  20. protected String defaultEncoding = null;   
  21. /**//* (non-Javadoc)   
  22. * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)   
  23. */   
  24. public void init(FilterConfig arg0) throws ServletException {   
  25. // TODO Auto-generated method stub   
  26. this.filterConfig = arg0;   
  27. this.defaultEncoding = filterConfig.getInitParameter("defaultencoding");   
  28. }   
  29. /**//* (non-Javadoc)   
  30. * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, 
    javax.servlet.ServletResponse, javax.servlet.FilterChain)   
  31. */   
  32. public void doFilter(   
  33. ServletRequest request,   
  34. ServletResponse response,   
  35. FilterChain chain)   
  36. throws IOException, ServletException {   
  37. // TODO Auto-generated method stub   
  38. request.setCharacterEncoding(selectEncoding(request));   
  39. chain.doFilter(request, response);   
  40. }   
  41. public void destroy() {   
  42.  
  43. this.defaultEncoding = null;   
  44. this.filterConfig = null;   
  45. }   
  46. protected String selectEncoding(ServletRequest request) {   
  47. return this.defaultEncoding;   
  48. }   
  49. }  

以上的相關內(nèi)容就是對Hibernate+MySQL 中文問題解決方案. 的介紹,望你能有所收獲。

【編輯推薦】

  1. MySQL雙向復制技術經(jīng)典版
  2. MySQL數(shù)據(jù)庫備份基礎知識匯總
  3. asp.net連接MySQL的正確操作流程
  4. 支持MySQL數(shù)據(jù)庫,SPL升級到3.2
  5. MySQL導入與導出.sql文件實操
責任編輯:佚名 來源: 互聯(lián)網(wǎng)
相關推薦

2010-05-17 09:49:46

MySQL中文問題

2010-05-12 09:08:49

Mysql中文

2010-06-07 14:50:50

jsp MySQL

2009-09-22 17:32:38

Hibernate A

2011-08-08 10:29:12

MySQL

2012-02-07 13:27:03

HibernateJava

2010-05-28 18:05:22

jsp MySQL

2009-09-21 17:10:14

struts Hibe

2010-05-24 18:22:36

jsp MySQL

2010-11-09 17:09:23

SQL Server中

2011-03-18 18:47:34

QtMySQL

2010-05-18 14:00:46

MySQL5.0中文問

2009-11-26 16:30:52

Suse中文亂碼問題

2011-02-24 10:48:51

FireFTP

2010-05-31 12:38:48

Nagios中文

2010-05-14 17:27:40

MySQL中文亂碼

2009-11-27 16:16:58

Suse中文編碼

2010-05-20 10:00:58

MySQL 中文亂碼

2011-07-20 18:00:15

MySQL數(shù)據(jù)庫字符集

2010-05-18 18:45:31

MySQL5.0中文問
點贊
收藏

51CTO技術棧公眾號