Eclispe下开发Struts完整解决乱码问题
{$PageTitle=}
【IT168技术文档】
Eclispe下开发Struts乱码问题非常令人头疼,下面给出几种解决方法:
主要有三个问题:
1.struts中资源文件中如果value为中文,显示乱码
解决办法:使用eclipse插件Properties Editor 更新站点http://propedit.sourceforge.jp/eclipse/updates/(建议自动更新)
步骤:
Eclipse下的“帮助”/“软件更新”/”查找并安装“/选择第二项/“新建远程站点”/name随意写,url输入http://propedit.sourceforge.jp/eclipse/updates/
2.在文本域里输入中文显示乱码
解决办法:使用servlet过滤器filter
最简单的可以借用tomcat下面的filters.SetCharacterEncodingFilter在自己的web.xml配置中加入tomcat中servlet_examples相应配置(高手可以自己配!)
本人配置如下
解决办法:把你要显示成中文的部分重新编码
例如:
【IT168技术文档】
Eclispe下开发Struts乱码问题非常令人头疼,下面给出几种解决方法:
主要有三个问题:
1.struts中资源文件中如果value为中文,显示乱码
解决办法:使用eclipse插件Properties Editor 更新站点http://propedit.sourceforge.jp/eclipse/updates/(建议自动更新)
步骤:
Eclipse下的“帮助”/“软件更新”/”查找并安装“/选择第二项/“新建远程站点”/name随意写,url输入http://propedit.sourceforge.jp/eclipse/updates/
2.在文本域里输入中文显示乱码
解决办法:使用servlet过滤器filter
最简单的可以借用tomcat下面的filters.SetCharacterEncodingFilter在自己的web.xml配置中加入tomcat中servlet_examples相应配置(高手可以自己配!)
本人配置如下
3.从某些数据库里读出乱码<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
![]()
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
解决办法:把你要显示成中文的部分重新编码
例如:
while (rs.next())...{
String col1 = rs.getString(1);
String col2 = rs.getString(2);
String col3 = rs.getString(3);
float col4 = rs.getFloat(4);
![]()
//convert character encoding
col1=new String(col1.getBytes("ISO-8859-1"),"GB2312");
col2=new String(col2.getBytes("ISO-8859-1"),"GB2312");
col3=new String(col3.getBytes("ISO-8859-1"),"GB2312");
}
0
相关文章
