/** ToUnicode. java */
Package com. edgewww. util;
Import java. io .*;
/**
* String Conversion to Unicode Code Class
* @ Author Jin Kui jsp (preferred for SUN Enterprise Applications) @ shanghai.com
* @ Date 2001-03-05
*/
Public class ToUnicode {
/**
* Convert a string to a Unicode code.
* @ Param strText the string to be converted
* @ Param code the encoding of the string before conversion, such as "GBK"
* @ Return the converted Unicode string
*/
Public String toUnicode (String strText, String code) throws UnsupportedEncodingException {
Char c;
String strRet = "";
Int intAsc;
String strHex;
StrText = new String (strText. getBytes ("8859_1"), code );
For (int I = 0; I <strText. length (); I ++ ){
C = strText. charAt (I );
IntAsc = (int) c;
If (intAsc & gt; 128 ){
StrHex = Integer. toHexString (intAsc );
StrRet = strRet + "& # x" + strHex + ";";
}
Else {
StrRet = strRet + c;
}
}
Return strRet;
}
}
/** Application example */
/** Gbk2Unicode. jsp (preferred for SUN Enterprise Applications )*/
<Meta http-equiv = "Content-Type" content = "text/html; charset = big5">
<Jsp (preferred for SUN Enterprise Applications): useBean id = "g2u" scope = "session" class = "com. edgewww. util. ToUnicode"/>
<% String lang = "this is simplified Chinese"; %>
<Br>
<% = Lang %>
<Br>
<% = G2u. toUnicode (lang, "GBK") %>