不知道你是否指的是中文文件名.我这里有一解决方法,需要反编译class文件,发现对返回给浏览器的另存文件名进行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();
    }

解决方案 »

  1.   

    发现很多人都使用 smart file uploader 来解决文件上传的问题, 但个人觉得 Common file uploader 更灵活, 如果你使用 struts 的话, 那就更不费吹灰之力了
      

  2.   

    同意楼上朋友的观点,虽然没用struts,仅仅使用file upload也觉得比其它的上传组件要好得多,而且还是free的
      

  3.   

    jspSmartUpload上传下载全攻略
    http://www.tongyi.net/article/20031015/200310153755.shtml记不清是第几次贴这个链接了。不经典可以找我索赔。