不是不去想办法解决,是想到的都做了,还是没解决:MulitpartRequest mr=new MultipartRequest(request,saveDir,maxSize,"gbk");String type=mr=getParameter("type");
out.println(type);
//在jsp里是正常的,因为jsp里有
//<%@page contentType="text/html;charset=gb2312"%>
//在servlet 里加上gb2312也可以,但就是写入数据库就是???
???何解???????????????/
数据库是mysql在插入数据库前就得新编码了!
String type=new String(mr.getParameter("type").getBytes("utf-8"),"gb2312");
或
String type=new String(mr.getParameter("type").getBytes("gb2312"),"gb2312");
或
String type=new String(mr.getParameter("type").getBytes("iso-8859-1"),"gb2312");过滤器//request.setCharacterEncoding("gb2312");
//中文转换
public static String toChinese(String str) {
if (str == null) {
return null;
}
try {
return new String(str.getBytes("iso-8859-1"), "gb2312");
}
catch (UnsupportedEncodingException ex) {
return "";
}
要是在CSDN没人解决的话,再也不来CSDN了
out.println(type);
//在jsp里是正常的,因为jsp里有
//<%@page contentType="text/html;charset=gb2312"%>
//在servlet 里加上gb2312也可以,但就是写入数据库就是???
???何解???????????????/
数据库是mysql在插入数据库前就得新编码了!
String type=new String(mr.getParameter("type").getBytes("utf-8"),"gb2312");
或
String type=new String(mr.getParameter("type").getBytes("gb2312"),"gb2312");
或
String type=new String(mr.getParameter("type").getBytes("iso-8859-1"),"gb2312");过滤器//request.setCharacterEncoding("gb2312");
//中文转换
public static String toChinese(String str) {
if (str == null) {
return null;
}
try {
return new String(str.getBytes("iso-8859-1"), "gb2312");
}
catch (UnsupportedEncodingException ex) {
return "";
}
要是在CSDN没人解决的话,再也不来CSDN了
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8");%> jsp传值到servlet,在servlet输出,显示为乱码的话,在servlet doGet方法内添加:
// 转编码
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF-8");通过链接传值,地址栏默认的编码方式是“iso-8859-1”,解决乱码,可以写一个方法,例如:
public String setCode(String str) throws UnsupportedEncodingException {
return new String(str.getBytes("ISO-8859-1"),"UTF-8");
}有时间,整理一下你的收获,感觉楼主解决问题后,并没有过多的延伸。要学,就要弄透它!还有一点,你没有任何权力要求任何人做任何事情,任何人也不会有义务替你做任何事情。这样的态度,相信即使不是CSDN,也不会有人理你。
or
<%request.setCharacterEncoding("GB2312");%>
就这个有问题