Topic: 还是关于Struts 的中文问题

  Print this page

1.还是关于Struts 的中文问题 Copy to clipboard
Posted by: jianhua23
Posted on: 2003-07-04 11:23

这个解决方案应该是可以了,将附件中的struts.jar 覆原有的 struts.jar 即可。
哈哈,简单吧!!!
提示: struts 是 1.0.2 版本,1.1 我还没来的急改

struts.jar (320.29k)

2.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: why
Posted on: 2003-07-04 11:41

What changes have you made?
Would you please kindly let us know? (though it's not hard to do a diff)

3.Re:还是关于Struts 的中文问题 [Re: why] Copy to clipboard
Posted by: jianhua23
Posted on: 2003-07-04 12:02

可以. 修改struts 1.0.2 源文件中的这个文件:
src\share\org\apache\struts\util\PropertyMessageResources.java
将第289行:
messages.put(messageKey(localeKey, key),props.getProperty(key));
改成下面的代码:
String sProps = props.getProperty(key);
try{
sProps = new String(sProps.getBytes("ISO-8859-1"),"GBK");
}
catch (Exception e){
e.printStackTrace();
}
messages.put(messageKey(localeKey, key),sProps);
然后重新编译生成新包。
一切 OK!!!!

4.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: jianhua23
Posted on: 2003-07-04 12:04

非常好的关于中文问题的文章

Java Web应用开发杂谈
http://www-900.ibm.com/developerWorks/cn/java/l-webjava/index.shtml

Java程序的国际化和本地化介绍
http://www-900.ibm.com/developerWorks/cn/java/joy-i18n/index.shtml

JSP/Servlet 中的汉字编码问题
http://www-900.ibm.com/developerworks/cn/java/jsp_dbcsz/

Java 编程技术中汉字问题的分析及解决
http://www-900.ibm.com/developerworks/cn/java/java_chinese/

Unicode 的多种表现形式
http://www-900.ibm.com/developerWorks/cn/unicode/utfencodingforms/

5.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: why
Posted on: 2003-07-04 12:12

期待大侠的1.1版修改档━━虽然小的暂时还未需要做中文案子Smile

相信floater会打分的,小的不敢越俎代庖啦!

6.Re:还是关于Struts 的中文问题 [Re: why] Copy to clipboard
Posted by: jianhua23
Posted on: 2003-07-04 12:52

我决不是什么大虾,我在我的单位有一个称呼我很喜欢--同学。
在论坛上的程序员不都是同学吗?!Smile

7.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: lihongtao
Posted on: 2003-07-04 12:53

不错

8.Re:还是关于Struts 的中文问题 [Re: lihongtao] Copy to clipboard
Posted by: alinew
Posted on: 2003-07-04 17:09

你这方法不太好吧。。只能算权宜之计
要是让你做一个同时支持GBK和Big5的你怎么办?

9.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: lihongtao
Posted on: 2003-07-04 17:19

可以写一个ant脚本来自动处理

10.Re:还是关于Struts 的中文问题 [Re: alinew] Copy to clipboard
Posted by: floater
Posted on: 2003-07-04 23:56

alinew wrote:
你这方法不太好吧。。只能算权宜之计
要是让你做一个同时支持GBK和Big5的你怎么办?

I agree with this. I would take a longer shot.

It's just a workaround. Also, you should talk to Struts folks(email) to see whether it's a bug.

I vaguely remember there is a bug somewhere in the code to cause a Chinese char problem, not sure it's the same one, not sure it's the right place to fix it.

But I am not quite satisfied with this hard-coded solution since it will create more problems later.

However, you earned your credit because you share it with all of us. The technical correctness is arguable and a different matter.

My 2 cents.

11.Re:还是关于Struts 的中文问题 [Re: why] Copy to clipboard
Posted by: floater
Posted on: 2003-07-04 23:59

why wrote:
期待大侠的1.1版修改档━━虽然小的暂时还未需要做中文案子Smile

相信floater会打分的,小的不敢越俎代庖啦!

Com'n, why, hehe... You have my admiration.

12.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: greeni
Posted on: 2003-07-05 10:36

我也是認為直接修改 struts 僅僅是權宜之計
這樣就剝奪了 struts support i18n 的功能了
另外, 如果 struts 只要有 bug-fix released 新的版本
勢必你就得修改一次

中文化的問題, 我建議還是在 filter 或採用 converter 來轉換
是比較好的方法
不過最好最好的方法則是直接採用 UTF-8 , not GB2312/Big5 and etc...

13.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: jorrey
Posted on: 2003-07-05 11:50

修改web.xml加入filter
<web-app>  
......
<filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>com.cj.encflt.EncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>gb2312</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
......
</web-app>

encflt.jar (1.15k)

14.Re:还是关于Struts 的中文问题 [Re: jianhua23] Copy to clipboard
Posted by: floater
Posted on: 2003-07-05 12:02

Someone mentioned this jar before.

Internally, I prefer unicode(don't try to the bytes, the bytes is much much cheaper than the human labor).

Externally, I prefer let users decide what they want to use.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923