这个问题比较复杂,但在WEB中编码的变化一般都是在GB2312、ISO-8859-1之间互换,你用下面的小程序试试:
public class ToHz
{
public static String gbToIso(String value)
{
if(value!=null)
{
try{
return new String(value.getBytes("GB2312"),"ISO-8859-1");
}catch(Exception e)
{
return "Error:"+e.getMessage();
}
}else{
return "";
}
} public static String isoToGb(String value)
{
if(value!=null)
{
try{
return new String(value.getBytes("ISO-8859-1"),"GB2312");
}catch(Exception e)
{
return "Error:"+e.getMessage();
}
}else{
return "";
}
}
}
public class ToHz
{
public static String gbToIso(String value)
{
if(value!=null)
{
try{
return new String(value.getBytes("GB2312"),"ISO-8859-1");
}catch(Exception e)
{
return "Error:"+e.getMessage();
}
}else{
return "";
}
} public static String isoToGb(String value)
{
if(value!=null)
{
try{
return new String(value.getBytes("ISO-8859-1"),"GB2312");
}catch(Exception e)
{
return "Error:"+e.getMessage();
}
}else{
return "";
}
}
}
* 将数据从数据库中取出后转换
*
* @param strVal 要转换的字符串
* @return 从“GBK”到“ISO8859_1”得到的字符串
*/
public static final String toISO(String strVal)
{
try
{
if(strVal==null)
{
return "";
}
else
{
strVal=new String(strVal.getBytes("GBK"), "ISO8859_1");
return strVal;
}
}
catch(Exception exp)
{
return "";
}
}
可不可以说一下?