我的数据库里保存了由浏览器提交的转义字符
怎样把他还原成源文这种乱码的源文是法文
这种乱码只有浏览器可以识别,应该属于html转义字符,
以下为数据库的乱码:
ë
ô
Æ
ç
¹
Ê
Ò
ëjava有转换函数吗?怎样把他还原成源文,郁闷很久了,非常感谢

解决方案 »

  1.   

    这个不能算“乱码”吧?这是 HTML 用来表示特殊字符的一种表示法,就是你说的“转义字符”。Java 有没有现成的转换函数我不清楚。有兴趣的话,按照下面的码表自己做一个转换程序吧 :)http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/charsets/charset2.asp
      

  2.   

    http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset1.asp,
    这个好像是我找得字符,怎么转过来呀,有人做过这个东西吗
      

  3.   

    做了个很粗糙的转换程序给你,只表示个大概的意思。
    另外,转换完的字符串是不能用来直接打印的(打印出来看上去是乱码,因为一般控制台不支持这个字符集)package test;import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test22 {    public static void main(String[] args) {
            String src = "hello, ë ô !";
            System.out.println(src);
            System.out.println(filterEntities(src));
        }    public static String filterEntities(String src) {
            StringBuffer sb = new StringBuffer();
            Pattern p = Pattern.compile("&[a-zA-Z]*;");
            Matcher m = p.matcher(src);
            int pos1 = 0;
            while (m.find(pos1)) {
                int pos2 = m.start();
                sb.append(src.substring(pos1, pos2));
                String entity = m.group().toLowerCase();
                if ("ë".equals(entity)) {
                    sb.append((char)203);
                } else if ("ô".equals(entity)) {
                    sb.append((char)212);
                } else {
                    sb.append("[UNKNOWN]");
                }
                pos1 = m.end();
            }
            sb.append(src.substring(pos1));
            return sb.toString();
        }
    }
      

  4.   

    我马上试试maquan('ma:kju)的转换程序。先谢谢了
      

  5.   

    经测试, 帮我写的程序可以转换了,
    现在将所有的转义字符贴在这里,供需要的朋友参考。
    太感谢maquan('ma:kju)
    特殊字符
    符号 实体 举例
    版权注释 © Copyright © 1999 W3C
    注册商标 ® MagiCo ®
    商标 ™ Webfarer™
    小于(Less than) &lt; <
    大于(Greater than) &gt; >
    Ampersand &amp; &
    nonbreaking space &nbsp;  
    破折号 &#8212; —
    引号(quotation) &quot; "一些实体表示拉丁文字符集Latin-1中的音标和杂符:  &nbsp; &#160; &ETH; &ETH; &#208;
    &iexcl; &iexcl; &#161; &Ntilde; &Ntilde; &#209;
    &cent; &cent; &#162; &Ograve; &Ograve; &#210;
    &pound; &pound; &#163; &Oacute; &Oacute; &#211;
    ¤ &curren; &#164; &Ocirc; &Ocirc; &#212;
    &yen; &yen; &#165; &Otilde; &Otilde; &#213;
    &brvbar; &brvbar; &#166; &Ouml; &Ouml; &#214;
    § &sect; &#167; × &times; &#215;
    ¨ &uml; &#168; &Oslash; &Oslash; &#216;
    &copy; &copy; &#169; &Ugrave; &Ugrave; &#217;
    &ordf; &ordf; &#170; &Uacute; &Uacute; &#218;
    &laquo; &laquo; &#171; &Ucirc; &Ucirc; &#219;
    &not; &not; &#172; &Uuml; &Uuml; &#220;
    &not; &shy; &#173; &Yacute; &Yacute; &#221;
    &reg; &reg; &#174; &THORN; &THORN; &#222;
    &macr; &macr; &#175; &szlig; &szlig; &#223;
    ° &deg; &#176; à &agrave; &#224;
    ± &plusmn; &#177; á &aacute; &#225;
    &sup2; &sup2; &#178; &acirc; &acirc; &#226;
    &sup3; &sup3; &#179; &atilde; &atilde; &#227;
    &acute; &acute; &#180; &auml; &auml; &#228;
    &micro; &micro; &#181; &aring; &aring; &#229;
    &para; &para; &#182; &aelig; &aelig; &#230;
    &#8226; &middot; &#183; &ccedil; &ccedil; &#231;
    &cedil; &cedil; &#184; è &egrave; &#232;
    &sup1; &sup1; &#185; é &eacute; &#233;
    &ordm; &ordm; &#186; ê &ecirc; &#234;
    &raquo; &raquo; &#187; &euml; &euml; &#235;
    &frac14; &frac14; &#188; ì &igrave; &#236;
    &frac12; &frac12; &#189; í &iacute; &#237;
    &frac34; &frac34; &#190; &icirc; &icirc; &#238;
    &iquest; &iquest; &#191; &iuml; &iuml; &#239;
    &Agrave; &Agrave; &#192; &eth; &eth; &#240;
    &Aacute; &Aacute; &#193; &ntilde; &ntilde; &#241;
    &Acirc; &Acirc; &#194; ò &ograve; &#242;
    &Atilde; &Atilde; &#195; ó &oacute; &#243;
    &Auml; &Auml; &#196; &ocirc; &ocirc; &#244;
    &Aring; &Aring; &#197; &otilde; &otilde; &#245;
    &AElig; &AElig; &#198; &ouml; &ouml; &#246;
    &Ccedil; &Ccedil; &#199; ÷ &divide; &#247;
    &Egrave; &Egrave; &#200; &oslash; &oslash; &#248;
    &Eacute; &Eacute; &#201; ù &ugrave; &#249;
    &Ecirc; &Ecirc; &#202; ú &uacute; &#250;
    &Euml; &Euml; &#203; &ucirc; &ucirc; &#251;
    &Igrave; &Igrave; &#204; ü &uuml; &#252;
    &Iacute; &Iacute; &#205; &yacute; &yacute; &#253;
    &Icirc; &Icirc; &#206; &thorn; &thorn; &#254;
    &Iuml; &Iuml; &#207; &yuml; &yuml; &#255;