Struts 的漢字顯示問題終結解決方案

1. 主要是屬性文件的字符轉換問題.具體步驟和檢測如下:
1) 用一般的編輯器輸入所要顯示的漢字
2) 使用Java JDK 下的native2ascii. 詳細說明見
 http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html

native2ascii - Native-to-ASCII Converter
Converts a file with native-encoded characters (characters which are non-Latin 1 and non-Unicode) to one with Unicode-encoded characters.
SYNOPSIS
native2ascii [options] [inputfile [outputfile]]

DESCRIPTION
The Java compiler and other Java tools can only process files which contain Latin-1 and/or Unicode-encoded (/udddd notation) characters. native2ascii converts files which contain other character encodings into files containing Latin-1 and/or Unicode-encoded charaters.
If outputfile is omitted, standard output is used for output. If, in addition, inputfile is omitted, standard input is used for input.

OPTIONS
-reverse
Perform the reverse operation: convert a file with Latin-1 and/or Unicode encoded characters to one with native-encoded characters.


-encoding encoding_name
Specify the encoding name which is used by the conversion procedure. The default encoding is taken from System property file.encoding. The encoding_name string must be taken from the first column of the table of supported encodings in the Supported Encodings document.

-Joption
Pass option to the Java virtual machine, where option is one of the options described on the reference page for the java application launcher. For example, -J-Xms48m sets the startup memory to 48 megabytes.


For encoding name you can reference:

http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html

For chinese use normally use: GBK, Big5. In Sun's encoding document, it is mentioned this conversion need: lib/rt.jar or lib/charsets.jar. These two file only can file Sun's JRE package. They cant find in Sun's JDK package.

但是我在轉換的時候沒有這兩個文件似乎也沒有問題.

Example: native2ascii -encoding GBK Inputfilename outputfilename

轉換後的校驗.
native2ascii 會因爲你的系統不同,可能會有不同的轉換結果. 如果發現問題,你可以去:
http://www.unicode.org/charts/ 查詢,依據目前的版本,你可以找到
East Asian Scripts-> Han ideographs->Unified CJK ideographs(5M)
http://www.unicode.org/charts/PDF/U4E00.pdf 這個文件.
下載後,你用PDF reader 的search功能找到你要轉換的漢字,比較轉換後的
字符是否正確,比如:我,在轉換後爲 /u6211.

所有的JSP文件採用UTF-8格式遍寫.並在文件頭強制:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

這樣你的問題就解決了.
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章