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相应配置(高手可以自己配!)
实例配置如下:
SetCharacterEncoding filters.SetCharacterEncodingFilter encoding GBK SetCharacterEncoding *.do
3,从某些数据库里读出乱码
解决办法:把你要显示成中文的部分重新编码
例如: 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"); }
|