软件环境:JDK1.4.2_09+Eclipse3.1+MS SQL SERVER200+SP3+JTDS1.0.2+Struts1.1+Hibernate3.0.5+Spring1.2.4。
由于刚开始学习这个Framework,所以很多东西也不是特别清楚,以前在JB环境下也没怎么遇到乱码问题。这次试了很多方法都不行,于是决定加个Fileter了,web.xml部分内容如下:
SetCharacterEncoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
GBK
SetCharacterEncoding
*.jsp
通过在Action中加断点调试,发现使用超连接的跳转是可以使用Filter的;但是如果是以.do为后缀的请求就不行了,抱着试试看的心理,我修改了web.xml:
context
org.springframework.web.context.ContextLoaderServlet
1
action
org.apache.struts.action.ActionServlet
config
/WEB-INF/struts-config.xml
debug
3
detail
3
0
action
*.do
SetCharacterEncoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
GBK
SetCharacterEncoding
*.jsp
SetCharacterEncoding
*.do
main.jsp
/WEB-INF/struts-bean.tld
/WEB-INF/struts-bean.tld
/WEB-INF/struts-html.tld
/WEB-INF/struts-html.tld
/WEB-INF/struts-logic.tld
/WEB-INF/struts-logic.tld
/WEB-INF/struts-template.tld
/WEB-INF/struts-template.tld
/WEB-INF/struts-tiles.tld
/WEB-INF/struts-tiles.tld
/WEB-INF/struts-nested.tld
/WEB-INF/struts-nested.tld
主要在这里多加了一个过滤内容!其他的,为防止万一,在页面(jsp)上也加了些东西:
<%@ page contentType="text/html; charset=GBK" pageEncoding="GBK"%>
呵呵,可以说是武装到牙齿了,开始调试:这次在Debug的时候,显示出从页面中传来的值终于不是乱码了,保存在数据库中后,也不是乱码。这个问题目前是部分解决了。因为我还没有测试在页面上哪些是不用写的,还有就是页面回现汉字是是否会有问题,不过这里先把自己的所得记录下来,如果有高人就此事谈论过,就算我孤陋寡闻吧,呵呵。
另外给出我的Hibernate.cfg.xml的部分内容:
jdbc:jtds:sqlserver://192.168.0.3:1433;DatabaseName=HomeConsume;charset=GBK
true
sju
sa
net.sourceforge.jtds.jdbc.Driver
org.hibernate.dialect.SQLServerDialect
【责编:admin】
--------------------next---------------------
阅读(216) | 评论(0) | 转发(0) |