高手请进,帮忙看一段代码,请发表自己的意见。
无意中看到了一个JAVA文件:CharsetMapping.java
我一时没看懂,请高手分析一下,是否可修改一下来处理JSP中的乱码问题呢?
/*
Copyright (C) 2002-2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
There are special exceptions to the terms and conditions of the GPL
as it is applied to this software. View the full text of the
exception exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
software distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.mysql.jdbc;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Mapping between MySQL charset names
* and Java charset names.
*
* I've investigated placing these in a .properties file,
* but unfortunately under most appservers this complicates
* configuration because the security policy needs to be changed
* by the user to allow the driver to read them :(
*
* @author Mark Matthews
*/
public class CharsetMapping {
//~ Static fields/initializers ---------------------------------------------
/**
* Mapping of Java charset names to MySQL charset names
*/
public static final Map JAVA_TO_MYSQL_CHARSET_MAP;
/**
* Mapping of upper-case Java charset names to MySQL charset names
*/
public static final Map JAVA_UC_TO_MYSQL_CHARSET_MAP;
/**
* Mapping of MySQL charset names to Java charset names
*/
public static final Map MYSQL_TO_JAVA_CHARSET_MAP;
/**
* Map/List of multibyte character sets (using MySQL names)
*/
public static final Map MULTIBYTE_CHARSETS;
/**
* Map of MySQL-4.1 charset indexes to Java encoding names
*/
public static final String[] INDEX_TO_CHARSET;
static {
HashMap tempMap = new HashMap();
tempMap.put("usa7", "US-ASCII");
tempMap.put("ascii", "US-ASCII");
tempMap.put("big5", "Big5");
tempMap.put("gbk", "GBK");
tempMap.put("sjis", "SJIS");
tempMap.put("gb2312", "EUC_CN");
tempMap.put("ujis", "EUC_JP");
tempMap.put("euc_kr", "EUC_KR");
tempMap.put("latin1", "ISO8859_1");
tempMap.put("latin1_de", "ISO8859_1");
tempMap.put("german1", "ISO8859_1");
tempMap.put("danish", "ISO8859_1");
tempMap.put("latin2", "ISO8859_2");
tempMap.put("czech", "ISO8859_2");
tempMap.put("hungarian", "ISO8859_2");
tempMap.put("croat", "ISO8859_2");
tempMap.put("greek", "ISO8859_7");
tempMap.put("latin7", "ISO8859_7");
tempMap.put("hebrew", "ISO8859_8");
tempMap.put("latin5", "ISO8859_9");
tempMap.put("latvian", "ISO8859_13");
tempMap.put("latvian1", "ISO8859_13");
tempMap.put("estonia", "ISO8859_13");
tempMap.put("dos", "Cp437");
tempMap.put("Cp850", "Cp850");
tempMap.put("Cp852", "Cp852");
tempMap.put("cp866", "Cp866");
tempMap.put("koi8_ru", "KOI8_R");
tempMap.put("koi8r", "KOI8_R");
tempMap.put("tis620", "TIS620");
tempMap.put("Cp1250", "Cp1250");
tempMap.put("Cp1250", "Cp1250");
tempMap.put("win1251", "Cp1251");
tempMap.put("cp1251", "Cp1251");
tempMap.put("cp1256", "Cp1256");
tempMap.put("win1251ukr", "Cp1251");
tempMap.put("cp1257", "Cp1257");
tempMap.put("macroman", "MacRoman");
tempMap.put("macce", "MacCentralEurope");
tempMap.put("utf8", "UTF-8");
tempMap.put("ucs2", "UnicodeBig");
tempMap.put("binary", "US-ASCII"); // closest match
MYSQL_TO_JAVA_CHARSET_MAP = Collections.unmodifiableMap(tempMap);
HashMap javaToMysqlMap = new HashMap();
Set keySet = MYSQL_TO_JAVA_CHARSET_MAP.keySet();
Iterator keys = keySet.iterator();
while (keys.hasNext()) {
Object mysqlEncodingName = keys.next();
Object javaEncodingName = MYSQL_TO_JAVA_CHARSET_MAP.get(mysqlEncodingName);
//
// Use 'closest' encodings here...as Java encoding names
// overlap with some MySQL character sets.
//
if ("ISO8859_1".equals(javaEncodingName)) {
if ("latin1".equals(mysqlEncodingName)) {
javaToMysqlMap.put(javaEncodingName, mysqlEncodingName);
}
} else if ("ISO8859_2".equals(javaEncodingName)) {
if ("latin2".equals(mysqlEncodingName)) {
javaToMysqlMap.put(javaEncodingName, mysqlEncodingName);
}
}
else if ("ISO8859_13".equals(javaEncodingName)) {
if ("latin7".equals(mysqlEncodingName)) {
javaToMysqlMap.put(javaEncodingName, mysqlEncodingName);
}
} else {
javaToMysqlMap.put(javaEncodingName, mysqlEncodingName);
}
}