最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

jsp中任意文字转Unicode的通用模块

日期:10-22    来源:中国设计秀    作者:cnwebshow.com

/** ToUnicode.java */ sD2中国设计秀
package com.edgewww.util; sD2中国设计秀
sD2中国设计秀
import java.io.*; sD2中国设计秀
sD2中国设计秀
/** sD2中国设计秀
* 字符串转换成Unicode码的类 sD2中国设计秀
* @author 栾金奎 jsp@shanghai.com sD2中国设计秀
* @date 2001-03-05 sD2中国设计秀
*/ sD2中国设计秀
public class ToUnicode { sD2中国设计秀
sD2中国设计秀
/** sD2中国设计秀
* 把字符串转换成Unicode码 sD2中国设计秀
* @param strText 待转换的字符串 sD2中国设计秀
* @param code 转换前字符串的编码,如"GBK" sD2中国设计秀
* @return 转换后的Unicode码字符串 sD2中国设计秀
*/ sD2中国设计秀
public String toUnicode(String strText,String code) throws UnsupportedEncodingException{ sD2中国设计秀
  char c; sD2中国设计秀
  String strRet = "" ; sD2中国设计秀
  int intAsc; sD2中国设计秀
  String strHex; sD2中国设计秀
  strText = new String(strText.getBytes("8859_1"),code); sD2中国设计秀
  for ( int i = 0; i < strText.length(); i++ ){ sD2中国设计秀
    c = strText.charAt(i); sD2中国设计秀
    intAsc = (int)c; sD2中国设计秀
    if(intAsc>128){ sD2中国设计秀
      strHex = Integer.toHexString(intAsc); sD2中国设计秀
      strRet = strRet + "&#x" + strHex+";"; sD2中国设计秀
    } sD2中国设计秀
    else{ sD2中国设计秀
      strRet = strRet + c; sD2中国设计秀
    } sD2中国设计秀
  } sD2中国设计秀
  return strRet ; sD2中国设计秀
} sD2中国设计秀
sD2中国设计秀
} sD2中国设计秀
sD2中国设计秀
/** 应用举例 */ sD2中国设计秀
/** gbk2Unicode.jsp */ sD2中国设计秀
<meta http-equiv="Content-Type" content="text/html; charset=big5"> sD2中国设计秀
<jsp:useBean id="g2u" scope="session" class="com.edgewww.util.ToUnicode"/> sD2中国设计秀
<% String lang = "这是简体中文"; %> sD2中国设计秀
<br> sD2中国设计秀
<%=lang %> sD2中国设计秀
<br> sD2中国设计秀
<%=g2u.toUnicode(lang,"GBK") %> sD2中国设计秀
sD2中国设计秀
 sD2中国设计秀

本文引用地址:/bc/article_46774.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明