加了上传图片的代码之后,中文存入数据库变成了问号?

cleanerjie 2006-12-07 11:00:29
我没加上传图片的代码之前,存入数据库的中文显示正常,可是加了上传图片的代码之后中文都变成了问号,究竟是怎么回事啊?
加了上传之后的代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,
java.sql.*,com.jspsmart.upload.*,java.util.*,cn.oof.database.*,cn.oof.house.*" errorPage="" %>
<jsp:useBean id="connBean" scope="page" class="beans.connDB"/>
<jsp:useBean id="chStr" class="beans.chStr" scope="page" />
<%!
String filename="";
int old_h=0;
int old_w=0;
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
String fileName2="";
String ext="";
String testvar="";
String url="web/bbs/uploadfile/images/";
%>
---------上传图片代码
<%
mySmartUpload.initialize(pageContext);
try

mySmartUpload.setAllowedFilesList("jpg,gif");
mySmartUpload.upload();
}
catch (Exception e){}
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
try{
为了方便看省略一部分代码......................................
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
FileOutputStream newimage=new FileOutputStream(newurl);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();

}
}
}
catch (Exception e)
{
e.toString();
}
%>


----------插入数据库
<%
request.setCharacterEncoding("GBK");
com.jspsmart.upload.Request req = mySmartUpload.getRequest();
int UID=Integer.parseInt(req.getParameter("UID"));
String title=chStr.chStr(req.getParameter("title"));
String face="face/"+chStr.chStr(req.getParameter("face"))+".gif";
String content=chStr.chStr(req.getParameter("content"));
String image_max="uploadfile/images/"+filename+"."+ext;
String image_min="uploadfile/images/"+filename+"_min."+ext;
-----------省略............................................
%>
title 和 content 都是问号
face是文件路径
到底怎么回事?????????
...全文
265 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
colinmok 2007-02-25
  • 打赏
  • 举报
回复
不好意思应该是public static String getStrFromISO(String str) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO-8859-1");
String temp = new String(temp_t, "GBK");
return temp;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
colinmok 2007-02-25
  • 打赏
  • 举报
回复
用这段吧public static String getStrFromISO(String str) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
String temp = new String(temp_t, "GBK");
return temp;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
wuch8237 2006-12-09
  • 打赏
  • 举报
回复
把从上传页面获取的值进行1下 编码转换(8859_1)之后再插入到数据库 就不会出现乱码了1
colinmok 2006-12-08
  • 打赏
  • 举报
回复
中文乱码
qqulijun 2006-12-08
  • 打赏
  • 举报
回复
把上传的文件名称进行编码转换
Sunny319 2006-12-08
  • 打赏
  • 举报
回复
页面的charset=gb2312"换成charset="GBK"
cleanerjie 2006-12-08
  • 打赏
  • 举报
回复
换成GBK也不行

81,092

社区成员

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

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