我没加上传图片的代码之前,存入数据库的中文显示正常,可是加了上传图片的代码之后中文都变成了问号,究竟是怎么回事啊?
加了上传之后的代码如下:
<%@ 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是文件路径
到底怎么回事?????????

解决方案 »

  1.   

    页面的charset=gb2312"换成charset="GBK"
      

  2.   

    用这段吧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;
      }
      

  3.   

    不好意思应该是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;
      }