Struts 亂碼主要有三個問題:
1,struts中資源文件中如果value為中文,顯示struts 亂碼
解決辦法:使用eclipse插件Properties Editor
2,在文本域里輸入中文顯示亂碼
解決辦法:使用servlet過濾器filter
最簡單的可以借用tomcat下面的filters.SetCharacterEncodingFilter在自己的web.xml配置中加入tomcat中servlet_examples相應(yīng)配置(高手可以自己配!)
本人配置如下:
SetCharacterEncoding filters.SetCharacterEncodingFilter
encoding
GBK
SetCharacterEncoding
*.do |
3,從某些數(shù)據(jù)庫里讀出亂碼
解決辦法:把你要顯示成中文的部分重新編碼
例如:
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亂碼問題得到解決。
【編輯推薦】
- 在Eclipse中開發(fā)struts應(yīng)用程序
- 手把手教你在Eclipse中配置開發(fā)Struts
- Eclipse下開發(fā)struts完整解決亂碼問題
- Struts相關(guān)背景介紹
- 使用Easy Struts for Eclipse開發(fā)Struts