用jspsmartupload上传下载文件,我在数据库中保存了文件的名称和路径,把文件上传到服务器的路径下,下载时根据数据库中保存的文件名称和路径下载文件。现在出现的问题时当下载中文文件名称的文件时名称是乱码,但是文件可以正常打开,请高手解决!我用tomcat3.2+jdk1.3和tomcat5.0+jdk1.5都是这样,但是我用jbuilder7编译(tomcat4.0)时名称确是正常的!

解决方案 »

  1.   

    我知道怎么解决中文问题!
    但你能不能告诉我!jspsmartupload是要放到jbuilder的哪个文件夹下?
    我弄了很久,若你能告诉我,我可以告诉你.
      

  2.   

    phil3302:我先问的,你得先解决我的问题啊
      

  3.   

    关注。
    网上不少资料都说到smartUpload中文乱码问题但我的情况似乎和楼主一样,上传没有问题,下载文件名乱码,既然乱码,为什么上传不乱码,只有下载才乱码?盼高手指点迷津
      

  4.   

    我有试了一下,用tomcat4是可以的,tomcat5和tomcat3都不行,难到tomcat最新的版本还不如旧版本?
      

  5.   

    给你吧!但你也要告诉我呀!!!!3、如何下载中文文件 jspSmartUpload虽然能下载文件,但对中文支持不足。若下载的文件名中有汉字,则浏览器在提示另存的文件名时,显示的是一堆乱码,很扫人兴。上面的例子就是这样。(这个问题也是众多下载组件所存在的问题,很少有人解决,搜索不到相关资料,可叹!) 为了给jspSmartUpload组件增加下载中文文件的支持,我对该组件进行了研究,发现对返回给浏览器的另存文件名进行UTF-8编码后,浏览器便能正确显示中文名字了。这是一个令人高兴的发现。于是我对jspSmartUpload组件的SmartUpload类做了升级处理,增加了toUtf8String这个方法,改动部分源码如下: public void downloadFile(String s, String s1, String s2, int i) throws ServletException, IOException, SmartUploadException    { if(s == null)     throw new IllegalArgumentException("File '" + s +     "' not found (1040)."); if(s.equals(""))     throw new IllegalArgumentException("File '" + s +     "' not found (1040)."); if(!isVirtual(s) && m_denyPhysicalPath)     throw new SecurityException("Physical path is     denied (1035)."); if(isVirtual(s))     s = m_application.getRealPath(s); java.io.File file = new java.io.File(s); FileInputStream fileinputstream = new FileInputStream(file); long l = file.length(); boolean flag = false; int k = 0; byte abyte0[] = new byte[i]; if(s1 == null)     m_response.setContentType("application/x-msdownload"); else if(s1.length() == 0)     m_response.setContentType("application/x-msdownload"); else     m_response.setContentType(s1); m_response.setContentLength((int)l); m_contentDisposition = m_contentDisposition != null ? m_contentDisposition : "attachment;"; if(s2 == null)     m_response.setHeader("Content-Disposition",      m_contentDisposition + " filename=" +      toUtf8String(getFileName(s))); else if(s2.length() == 0)     m_response.setHeader("Content-Disposition",      m_contentDisposition); else     m_response.setHeader("Content-Disposition",      m_contentDisposition + " filename=" + toUtf8String(s2)); while((long)k < l) {     int j = fileinputstream.read(abyte0, 0, i);     k += j;     m_response.getOutputStream().write(abyte0, 0, j); } fileinputstream.close();    }    /**     * 将文件名中的汉字转为UTF8编码的串,以便下载时能正确显示另存的文件名.     * 纵横软件制作中心雨亦奇2003.08.01     * @param s 原文件名     * @return 重新编码后的文件名     */    public static String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i=0;i<s.length();i++) {     char c = s.charAt(i);     if (c >= 0 && c <= 255) { sb.append(c);     } else { byte[] b; try {     b = Character.toString(c).getBytes("utf-8"); } catch (Exception ex) {     System.out.println(ex);     b = new byte[0]; } for (int j = 0; j < b.length; j++) {     int k = b[j];     if (k < 0) k += 256;     sb.append("%" + Integer.toHexString(k).     toUpperCase()); }     } } return sb.toString();    }
     
    注意源码中粗体部分,原jspSmartUpload组件对返回的文件未作任何处理,现在做了编码的转换工作,将文件名转换为UTF-8形式的编码形式。UTF-8编码对英文未作任何处理,对中文则需要转换为%XX的形式。toUtf8String方法中,直接利用Java语言提供的编码转换方法获得汉字字符的UTF-8编码,之后将其转换为%XX的形式。 将源码编译后打包成jspSmartUpload.jar,拷贝到Tomcat的shared/lib目录下(可为所有WEB应用程序所共享),然后重启Tomcat服务器就可以正常下载含有中文名
      

  6.   

    如果有改好的jar包(经过实践考验的),发一个我邮箱谢谢了 [email protected]自己该,没有兴趣,弄不好该的一塌糊涂:(