jsp+sql server的中文乱码问题.拜托了各位 谢谢

2024-12-26 16:31:24
推荐回答(3个)
回答1:

package com.yourcompany.struts.util; import java.io.UnsupportedEncodingException; public class Exchange { public static final String ENCODE = "ISO-8859-1"; public static final String CNCODE = "gbk"; public static String toCn(String value) { String cnString; try { cnString = new String(value.getBytes(ENCODE), CNCODE); return cnString; } catch (UnsupportedEncodingException e) { // TODO 自动生成 catch 块 e.printStackTrace(); return null; } } }

回答2:

package com.core; public class ChStr { public static String toChinese(String strvalue) { try { if (strvalue == null) { return ""; } else { strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK").trim(); return strvalue; } } catch (Exception e) { return ""; } }

回答3:

首先你要看看你的编码格式SQL的默认编码格式好象是UTF-8!