我在提交页面上设置了UTF-8编码。来到servlet后转成GB2312.结果还是乱码..有什么好的办法不让上传的时候中文字会乱码的..??什么编码都试过。上传后的文件名还是乱码..我刚换的IE8。绝对没问题.请大家帮帮忙吧。这问题困扰了很久。谢谢
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
           try { 
              SmartUpload su = new SmartUpload();
              su.initialize(config, request, response);
              su.setMaxFileSize(1024 * 1024 * 4); //4M 
              su.upload();
              String path = "d:/upload";
              for (int i = 0; i < su.getFiles().getCount(); i++) {
                   com.jspsmart.upload.File file = su.getFiles().getFile(i);
                   fileName = file.getFileName();
                   fileName = new String(fileName.getBytes("ISO-8859-1"),"GB2312");
                   out.print(fileName);

解决方案 »

  1.   

    fileName = new String(fileName.getBytes("ISO-8859-1"),"GB2312");将后面的"GB2312"去掉,直接
     
    fileName = new String(fileName.getBytes("ISO-8859-1"));
      

  2.   

    还是不行吧。。兄弟/打印出来还是.
    ???.jpg
      

  3.   

    response.setContentType("text/html;charset=GB2312");
    这里的charset=GB2312 ,我近几天也在看Jsp,刚在书上看到charset和Charset是有区别的,你换大写的试试。
    书上说避免汉字出现乱码的方式有两种
    1:即将其中出现Charset中的首写字母(C为大写字母)
    1:将字符串str用ISO-8895-1重新编码,存储在字节数组中,然后将数组转化为字符串
    byte b[] = str.getBytes("ISO-8895-1");
    str = new String(b);
      

  4.   

    response.setCharacterEncoding("GB2312");这句试试
      

  5.   

     可以看看这个,希望对你有帮助。。
    http://wudale.bokee.com/3594651.html
      

  6.   

    这个是SmartUpload的问题
    可以在前台页面对文件名进行url编码
      

  7.   

    fileName = new String(fileName.getBytes("GBK"),"GBK");
    试试