关于struts中文转换问题包括ApplicationResources.properties和text
在struts中,
我在ApplicationResource.properties中写入中文信息,例如有一条信息
“部门增加成功”,
现在我进行增加时,在jsp页面的html:text标签中输入中文,点击增加后
提示信息出现:????? html:text中显示的也是???????????
请问这个问题如何处理?
我是按照下面这样做的:
(1)、将struts-config.xml的字体编码<?xml version="1.0" encoding="UTF-8"?>修改成<?xml version="1.0" encoding="ISO_8859_1"?>
(2)、将jsp页面的成<%@ page contentType="text/html; charset=GBK" %>修改成<%@ page contentType="text/html; charset=ISO_8859_1" %>
然后我写一个转换函数
public static String toChinese(String str) {
try {
return new String(normalizeString(str).getBytes("ISO8859_1"), "gb2312");
}
catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
return null;
}
}
private static String normalizeString( String strValue )
{
return ( ( strValue == null ) ? "" : strValue.trim() ) ;
}
}
将html:text中的内容转换成中文,
但我重新增加的时候,ApplicationResource.properties的提示信息能正常显示,增加后html:text的内容也正常显示,但是下拉框中的中文全部变成乱码,下拉框中我也转换了的。