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

2016-01-29 12:08 34 1 收藏

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

【 tulaoshi.com - Java 】

  /** 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(intAsc128){
      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") %

 

来源:https://www.tulaoshi.com/n/20160129/1484800.html

延伸阅读
标签: Java JAVA基础
  信息发布界面 提供发布信息的交互界面,调用 recordMessage.jsp程序。   sayMessage.jsp   <HTML <HEAD <TITLE 信息发布</TITLE   <META content = "text/html; charset=GB2312" http-equiv = Content-Type <LINK href ="css_01.css" rel = stylesheet <...
标签: Web开发
package com.shaccp.web.util; import java.util.List; public class PageBean { /** * * * @author ppy 2008-10-18 14:3:56 * totalRecords 总记录数 * list 保存分页的数据 * pageNo 当前页 * pageSize 页大小 * query 保存用户查询的字符串 * pageAction 操作分页的Servlet或Action(struts) * method (struts中Action对应的meth...
【PS文字特效tulaoshi】PS制作创意文字标志 先来看看最终的效果图吧: 具体的制作步骤如下: 1,最终效果; 2,对背景进行径向渐变(#2d2d2d--#101010); 新建一层,使用彩虹渐变(颜色要比默认的彩虹色要深,使用线型渐变);将此层改为叠加图层模式; 【PS文字特效】PS制作创意文字标志(2) 3,输入文字;再将...

经验教程

564

收藏

92
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部