Eclipse工具下开发解决Struts 乱码的问题

Struts 乱码主要有三个问题:

1,struts中资源文件中如果value为中文,显示struts 乱码

解决办法:使用eclipse插件Properties Editor

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);

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");

----

}

至此Struts乱码问题得到解决。

【编辑推荐】

  1. 在Eclipse中开发struts应用程序
  2. 手把手教你在Eclipse中配置开发Struts
  3. Eclipse下开发struts完整解决乱码问题
  4. Struts相关背景介绍
  5. 使用Easy Struts for Eclipse开发Struts
THE END