快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

JSP中任意文字转UNICODE的通用模块

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

import java.io.*;

/**
* 字符串转变成Unicode码的类
*/
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") %>
返回类别: 教程
上一教程: TOMCAT的初学体验
下一教程: JSP+JAVABEAN循序渐进教程(五)

您可以阅读与"JSP中任意文字转UNICODE的通用模块"相关的教程:
· 多中WEB服务器的通用JSp源代码暴露漏洞
· 穷人的通用OLAP方案III--JPivot表现层
· Allaire JRUN 2.3 查看任意文件漏洞
· SERVLET和JSP的通信的一种方式
· Apache泄露重写的任意文件漏洞 
    微笑服务 优质保证 索取样品