求助高手,servlet 乱码问题

seeshuai 2006-09-26 07:59:54
我在servlet提取表单数据时,为什么插入不会出现乱码,而更新时却会乱码呢,出现的乱码是 繁
&#和后面的;是固定的,而数字则根据汉字的改变而改变, 我已经有加了 request.setCharacterEncoding("gb2312") 哪位高手遇到过这情况帮忙下,谢谢了!
...全文
191 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
feihuchina 2006-09-27
  • 打赏
  • 举报
回复


/**
* 字符串内码转换 GB2312 to iso8859-1
* @param ori 源字符串
* @return 转换后的字符串
*/
public static String gbtoiso(String ori) {
String newstr = "";
try {
if (ori == null) {
ori = "";
}
byte[] byte1 = null;
byte1 = ori.getBytes("EUC_CN");
newstr = new String(byte1, "ISO-8859-1");
return newstr;
}
catch (Exception e) {
e.printStackTrace();
return newstr;
}
}
feihuchina 2006-09-27
  • 打赏
  • 举报
回复

/**
* 字符串内码转换 iso8859-1 to GB2312
* @param ori 源字符串
* @return 转换后的字符串
*/
public static String isotoutf8(String ori) {
String newstr = "";
try {
if (ori == null) {
ori = "";
}
byte[] byte1 = null;
byte1 = ori.getBytes("ISO-8859-1");
newstr = new String(byte1, "utf-8");
return newstr;
}
catch (Exception e) {
e.printStackTrace();
return newstr;
}
}
feihuchina 2006-09-27
  • 打赏
  • 举报
回复
一般通过request传输后的值都需转码,没写代码不知你程序是如何实现的,我给你两个方法吧,你都试一下
/**
* 字符串内码转换 iso8859-1 to GB2312
* @param ori 源字符串
* @return 转换后的字符串
*/
public static String isotogb(String ori) {
String newstr = "";
try {
if (ori == null) {
ori = "";
}
byte[] byte1 = null;
byte1 = ori.getBytes("ISO-8859-1");
newstr = new String(byte1, "EUC_CN");
return newstr;
}
catch (Exception e) {
e.printStackTrace();
return newstr;
}
}
happyzhu 2006-09-26
  • 打赏
  • 举报
回复
贴代码看看!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧