软件环境JDK_+Eclipse+MS SQL SERVER+SP+JTDS+Struts+Hibernate+Spring
由于刚开始学习这个Framework所以很多东西也不是特别清楚以前在JB环境下也没怎么遇到乱码问题这次试了很多方法都不行于是决定加个Fileter了webxml部分内容如下
<filter>
<filtername>SetCharacterEncoding</filtername>
<filterclass>
orgspringframeworkwebfilterCharacterEncodingFilter</filterclass>
<initparam>
<paramname>encoding</paramname>
<paramvalue>GBK</paramvalue>
</initparam>
</filter>
<! 要过滤得类型 >
<filtermapping>
<filtername>SetCharacterEncoding</filtername>
<urlpattern>*jsp</urlpattern>
</filtermapping>
通过在Action中加断点调试发现使用超连接的跳转是可以使用Filter的但是如果是以do为后缀的请求就不行了抱着试试看的心理我修改了webxml
<?xml version= encoding=UTF?>
<webapp>
<!Spring ApplicationContext>
<servlet>
<servletname>context</servletname>
<servletclass> orgsprntextContextLoaderServlet
</servletclass>
<loadonstartup></loadonstartup>
</servlet>
<servlet>
<servletname>action</servletname>
<servletclass>orgapachestrutsactionActionServlet</servletclass>
<initparam>
<paramname>config</paramname>
<paramvalue>/WEBINF/strutsconfigxml</paramvalue>
</initparam>
<initparam>
<paramname>debug</paramname>
<paramvalue></paramvalue>
</initparam>
<initparam>
<paramname>detail</paramname>
<paramvalue></paramvalue>
</initparam>
<loadonstartup></loadonstartup>
</servlet>
<servletmapping>
<servletname>action</servletname>
<urlpattern>*do</urlpattern>
</servletmapping>
<filter>
<filtername>SetCharacterEncoding</filtername>
<filterclass>
orgspringframeworkwebfilterCharacterEncodingFilter</filterclass>
<initparam>
<paramname>encoding</paramname>
<paramvalue>GBK</paramvalue>
</initparam>
</filter>
<! 要过滤得类型 >
<filtermapping>
<filtername>SetCharacterEncoding</filtername>
<urlpattern>*jsp</urlpattern>
</filtermapping>
<filtermapping>
<filtername>SetCharacterEncoding</filtername>
<urlpattern>*do</urlpattern>
</filtermapping>
<welcomefilelist>
<welcomefile>mainjsp</welcomefile>
</welcomefilelist>
<taglib>
<tagliburi>/WEBINF/strutsbeantld</tagliburi>
<tagliblocation>/WEBINF/strutsbeantld</tagliblocation>
</taglib>
<taglib>
<tagliburi>/WEBINF/strutshtmltld</tagliburi>
<tagliblocation>/WEBINF/strutshtmltld</tagliblocation>
</taglib>
<taglib>
<tagliburi>/WEBINF/strutslogictld</tagliburi>
<tagliblocation>/WEBINF/strutslogictld</tagliblocation>
</taglib>
<taglib>
<tagliburi>/WEBINF/strutstemplatetld</tagliburi>
<tagliblocation>/WEBINF/strutstemplatetld</tagliblocation>
</taglib>
<taglib>
<tagliburi>/WEBINF/strutstilestld</tagliburi>
<tagliblocation>/WEBINF/strutstilestld</tagliblocation>
</taglib>
<taglib>
<tagliburi>/WEBINF/strutsnestedtld</tagliburi>
<tagliblocation>/WEBINF/strutsnestedtld</tagliblocation>
</taglib>
</webapp>
主要在这里多加了一个过滤内容!其他的为防止万一在页面(jsp)上也加了些东西
<%@ page contentType=text/html; charset=GBK pageEncoding=GBK%>
<meta httpequiv=contenttype content=text/html; charset=GBK>
呵呵可以说是武装到牙齿了开始调试这次在Debug的时候显示出从页面中传来的值终于不是乱码了保存在数据库中后也不是乱码这个问题目前是部分解决了因为我还没有测试在页面上哪些是不用写的还有就是页面回现汉字是是否会有问题不过这里先把自己的所得记录下来如果有高人就此事谈论过就算我孤陋寡闻吧呵呵
另外给出我的Hibernatecfgxml的部分内容
<sessionfactory>
<property name=nnectionurl>jdbc:jtds:sqlserver://:;DatabaseName=HomeConsume;charset=GBK</property>
<property name=hibernatecglibuse_reflection_optimizer>true</property>
<property name=nnectionpassword>sju</property>
<property name=nnectionusername>sa</property>
<property name=nnectiondriver_class>netsourceforgejtdsjdbcDriver</property>
<property name=hibernatedialect>orghibernatedialectSQLServerDialect</property>
<mapping resource=net/magicyang/homeconsume/pojo/Testhbmxml />
<mapping resource=net/magicyang/homeconsume/pojo/Consumeinfohbmxml />
<mapping resource=net/magicyang/homeconsume/pojo/Consumetypehbmxml />
</sessionfactory>