关于struts中文转换问题包括ApplicationResources.properties和text

qjhaaaaa 2003-10-20 07:25:19
在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的内容也正常显示,但是下拉框中的中文全部变成乱码,下拉框中我也转换了的。



...全文
98 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shoopman 2004-01-15
  • 打赏
  • 举报
回复
mark
qjhaaaaa 2003-10-21
  • 打赏
  • 举报
回复
我的问题解决了:
第一步:
将ApplicationResources.properties 拷到jdk/bin目录下,运行
native2ascii -encoding gb2312 ApplicationResources.properties ApplicationResources_zh.properties,
第二步:
然后将struts-config.xml中修改成
<message-resources null="false" parameter="ApplicationResources_zh" />
从ApplicationResource.properties中文问题就解决了。
第三步:
写一个函数
public class Function {
public Function() {
}

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

}
将表单输入输出的转换成中文
就解决了
w1w1w1w 2003-10-20
  • 打赏
  • 举报
回复
我的做法是这样:
在ApplicationResource.properties的同级目录下做一个bat文件,bat的内容如下:
“native2ascii -encoding gb2312 E:\dev\TomcatSite\src\ApplicationResources.properties ApplicationResources_zh.properties”;
---------------------------------------------------
并且并不影响你在ApplicationResources.properties做修改;在编译前先执行这个命令.

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧