JSTL+Spring+Hibernate中文亂碼問題

华生豆 2005-03-19 09:08:42
初學Spring和Hibernate,做了一個小系統,遇到了這個比較頭疼的中文亂碼問題,已經搜索了很多文章,做了很多嘗試,都不能解決~~~

包括:
web.xml中加入:

<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>big5</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>



*-servlet.xml中加入:

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/JSP/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
<property name="contentType">
<value>text/html;charset=big5</value>
</property>
</bean>


*.jsp文件中添加:

<%@page contentType="text/html;charset=big5"%>

<meta http-equiv="Content-Type" content="text/html; charset=big5">


因爲我是繁體系統,所以都使用big5編碼,我換成UTF-8和GBK問題依舊,當我新增記錄時就是出現亂碼,數據庫中存的也是亂碼,但是數據庫是可以新增繁體中文記錄的,奇怪的是我用jxl做的一個excel數據導入的功能,可以把繁體中文導入數據庫,沒有亂碼出現,在頁面也可以正常顯示~~~

敢問各位,是哪裏出了問題了呢?Spring還是Hibernate?該如何解決呢?

數據庫是MS SQL Server~~~
...全文
189 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
华生豆 2005-04-13
  • 打赏
  • 举报
回复
終于自己解決此問題,把解決辦法說一下,給大家借鑑~~~

我用的類是extends SimpleFormController,我猜測是在Person person = (Person) cmd;時就已亂碼,經測試果然如此,於是,在其後加了一個處理,person.setPname(new String(person.getPname().getBytes(),"big5"));就可以正確的存入繁體中文~~~

不知大家是否還有更好解決辦法,我發現用過濾器也不行,只能手動加這個處理~~~
schee 2005-03-30
  • 打赏
  • 举报
回复
楼上说的是,
用SetEncodingFilter过滤;
华生豆 2005-03-30
  • 打赏
  • 举报
回复
没有人能指点一下的吗~~~
华生豆 2005-03-29
  • 打赏
  • 举报
回复
樓上的用的是tomcat自帶的那個filter吧,不管用的~~~
zlhlj2000 2005-03-29
  • 打赏
  • 举报
回复
web.xml
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>big5</param-value>
</init-param>
</filter>
<filter>
只在web.xml和页面中加就可以了。
华生豆 2005-03-28
  • 打赏
  • 举报
回复
我用的是resin,不是tomcat

另,我试过UTF-8,一样是乱码~~~
waterye 2005-03-24
  • 打赏
  • 举报
回复
tomcat_home\conf\server.xml

<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK" />

注意URIEncoding="GBK"
miaoliujun 2005-03-24
  • 打赏
  • 举报
回复
全部用UTF-8吧,你还是BIG5呢,呵呵
fashchina 2005-03-24
  • 打赏
  • 举报
回复
UP
jianghuxing 2005-03-24
  • 打赏
  • 举报
回复
tomcat_home\conf\server.xml

<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK" />

注意URIEncoding="GBK"

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧