天天看點

jsp中任意文字轉Unicode的通用子產品

package com.edgewww.util;

import java.io.*;

public class ToUnicode {

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>128){

      strHex = Integer.toHexString(intAsc);

      strRet = strRet + "" + strHex+";";

    }

    else{

      strRet = strRet + c;

JAVA天堂

    }

  }

  return strRet ;

}

}

<% String lang = "這是簡體中文"; %>

<%=lang %>

<%=g2u.toUnicode(lang,"GBK") %>

全文閱讀:http://www.javah.net/JSP_JSF/20070511/1051.html