Universal module for Unicode in any text in JSP

Source: Internet
Author: User
/** Tounicode.java * *
Package com.edgewww.util;

Import java.io.*;

/**
* A class that converts a string into a Unicode code
* @author Sukinqui jsp@shanghai.com
* @date 2001-03-05
*/
public class Tounicode {

/**
* Convert string to Unicode code
* @param strText strings to be converted
* @param code for the string before the code conversion, such as "GBK"
* @return converted Unicode code string
*/
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;
}

}

/** Application Examples * *
/** 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 = "This is Simplified Chinese"; %>
<br>
<%=lang%>
<br>
<%=g2u.tounicode (lang, "GBK")%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.