有关手机中文问题传输的解决办法

文章作者 100test 发表时间 2007:03:14 17:40:59
来源 100Test.Com百考试题网


/**
* Write the String data
*
* @param out
* @param value
*/
public static void writeUnicode(final DataOutputStream out, final String value) throws ActionException {
try {
final String unicode = StringFormatter.gbEncoding( value ).
final byte[] data = unicode.getBytes().
final int dataLength = data.length.

System.out.println( "Data Length is: " dataLength ).
System.out.println( "Data is: " value ).
out.writeInt( dataLength ).
out.write( data, 0, dataLength ).
} catch (IOException e) {
throw new ActionException( IMDefaultAction.class.getName(), e.getMessage() ).
}
}
--------------------------------------------------------------------------------

----------------------------------------------------------------------
以下代码是gbEncoding()方法,把双字节字符转换成\uXXXX,ASIIC码在前面补00。
----------------------------------------------------------------------
/**
* This method will encode the String to unicode.
*
* @param gbString
* @return
*/

代码:--------------------------------------------------------------------------------
public static String gbEncoding( final String gbString ) {
char[] utfBytes = gbString.toCharArray().
String unicodeBytes = "".
for( int byteIndex = 0. byteIndex < utfBytes.length. byteIndex ) {
String hexB = Integer.toHexString( utfBytes[ byteIndex ] ).
if( hexB.length() <= 2 ) {
hexB = "00" hexB.
}
unicodeBytes = unicodeBytes "\\u" hexB.
}
System.out.println( "unicodeBytes is: " unicodeBytes ).
return unicodeBytes.
}
--------------------------------------------------------------------------------

----------------------------------------------------------------------
在客户端收到服务器的数据,先将其一个一个字符解码。双字节显示正常。

相关文章


JAVA认证历年真题:SCJP认证套题解析[1]
SCJDInformation
scjp(sun认证java程序员)来谈谈我的复习方法
我看SCJP考试通过
有关手机中文问题传输的解决办法
走上Java认证考试学习之旅
我的struts分页算法的实现
冷静面对越炒越热的Java培训市场
Java开源软件四大帮派
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛