动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Jsp → 阅读文章

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

作者来源: 
阅读 1244 人次 , 2006-3-29 4:23:00 


/** tounicode.java */
package com.edgewww.util;

import java.io.*;

/**
* 字符串转换成unicode码的类
* @author 栾金奎 jsp@shanghai.com
* @date 2001-03-05
*/
public class tounicode {

/**
* 把字符串转换成unicode码
* @param strtext 待转换的字符串
* @param code 转换前字符串的编码,如"gbk"
* @return 转换后的unicode码字符串
*/
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 + "&#x" + strhex+";";
    }
    else{
      strret = strret + c;
    }
  }
  return strret ;
}

}

/** 应用举例 */
/** gbk2unicode.jsp */
<meta http-equiv="content-type" content="text/html; charset=big5">
<jsp:usebean id="g2u" scope="session" class="com.edgewww.util.tounicode"/>
<% string lang = "这是简体中文"; %>
<br>
<%=lang %>
<br>
<%=g2u.tounicode(lang,"gbk") %>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:java/jsp中 中文问题详解
· 下一篇:javamail在jsp中调用
· JSP中的TagLib应用(1)
· JSWDK环境安装与配置 
· 在Linux环境下安装JSP
· 关于JSP中文问题的解决方法
· JSP技巧:发送动态图像(3)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077