to bigbuiding () :我的问题好象与你遇到的相似,能否告解你是怎么处理的?

解决方案 »

  1.   

    lhyao (茅台) 遇到同样的问题,如下:
    我使用jspSmartLoad在上传文件文件的时候问题不大,在下载的时候发现如果文件的大小一旦小于64k的时候,下载就会报错:org.apache.jasper.JasperException: getOutputStream() has already been called for this responsejava.lang.IllegalStateException: getOutputStream() has already been called for this response而文件大小只要超过64k就会一些OK了,真是不明白。我是使用struts来开发的,在jspSmartLoad中打上断点,中间不会报错,流程也会走完,就是到了最后显示下载的时候出现问题。真的很郁闷!
    解决:
    改动代码:
    public class SmartUpload
    {
    ...
    public void downloadFile(String s, String s1, String s2, int i)
    {
    ...
    while ((long) k < l) 
    {
        int j = fileinputstream.read(abyte0, 0, i);
        k += j;
        m_response.getOutputStream().write(abyte0, 0, j);
        //添加以下代码
        m_response.flushBuffer();
    }
    ...
    }
    ...
    }
    解决中文文件名下载问题(含小于64K小文件下载问题):
    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);
               //解决小于64K文件的下载错误的问题(清一下缓存就行了)
               m_response.flushBuffer();
    }
    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();
        }
      

  2.   

    小颖JAVA源代码反编译超级引挚 V1.4 标准版  
    http://www.kxia.com/soft/16338.htm
      

  3.   

    问题已经解决,并且解决了中文问题以及小于64K出错的问题,并重新编译了jspsmart类,如果那位想要将发邮件到[email protected]索取!太高兴了,感谢lhyao (茅台)的提示以及雨亦奇的代码!谢谢
      

  4.   

    上面代码有个bug,解决了小于64K文件的问题,又去出现了大文件内存溢出的问题,现将类修改如下:
        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);
                   //解决小于64K文件的下载错误的问题(清一下缓存就行了)
                   if(this.getSize()<=64*1024)
                   m_response.flushBuffer();
                }
                fileinputstream.close();
          }