最近使用jspSmartUpload的上传下载功能,但对中文文件名不支持,后来再网上找到一个修改了的包,支持中文文件名,但又有新的问题,上传之后的文件如果直接使用超连接的形式下载会提示无法打开站点文件,但英文文件名的可以正常下载。我有使用jspSmartUpload下载,中文word文档可以下载,但英文的就不行了,抛出异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
但中文文件名的rar文档,也出现上面的异常。这个异常是怎么产生的?
还有,word文档可以下载,但在保存的时候,文件名和文档类型不对,获取不到正确的文件名,如果选择打开选项,可以正确打开word文档,这个应该怎么解决?
jspSmartUpload上传的文件可以按照某种规则重命名吗?
请大家帮忙解决一下,谢谢!

解决方案 »

  1.   

    抛出异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
    这个异常和中英文没关系,在读之前调用一下 response.reset()方法就行了。具体看看servlet规范,他上面就说明。
    The servlet can request a preferred buffer size by using the setBufferSize
    method. The buffer assigned is not required to be the size requested by the servlet,
    but must be at least as large as the size requested. This allows the container to
    reuse a set of fixed size buffers, providing a larger buffer than requested if
    appropriate. The method must be called before any content is written using a
    ServletOutputStream or Writer. If any content has been written or the response
    object has been committed, this method must throw an IllegalStateException.
    The isCommitted method returns a boolean value indicating whether any
    response bytes have been returned to the client. The flushBuffer method forces
    content in the buffer to be written to the client.
    The reset method clears data in the buffer when the response is not
    committed. Headers and status codes set by the servlet prior to the reset call must
    be cleared as well. The resetBuffer method clears content in the buffer if the
    response is not committed without clearing the headers and status code.
    If the response is committed and the reset or resetBuffer method is called,
    an IllegalStateException must be thrown. The response and its associated
    buffer will be unchanged.
      

  2.   

    <%@ page contentType="text/html; charset=GB2312" language="java"
        import="java.sql.*"
        import="java.util.*,
    com.jspsmart.upload.*"
        import="com.document.*,
                com.util.*"  %><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><%
    mySmartUpload.initialize(pageContext); boolean foundErr = false;
    String myFileName = "";
    String uploadPath = "";
    String errMsg=""; //com.jspsmart.upload.Request req = mySmartUpload.getRequest();
    String path = request.getParameter("path");
    String docName = request.getParameter("name");
    int usr_right = CommonUtil.changeToInt(request.getParameter("usr_right"));
    int doc_right = CommonUtil.parseInt(request.getParameter("doc_right"));
    String documentPath = getServletContext().getInitParameter("document");
    String doc_dep_id = request.getParameter("doc_dep");
    String depself = request.getParameter("depself");
    String dep_id = session.getAttribute(Constants.LOGON_USER_DEP_ID).toString();
    if (……) {}else {
        mySmartUpload.setContentDisposition(null);
        mySmartUpload.downloadFile(path,"application/msword",docName, 1024);
        out.close();
    }
    %>
      

  3.   

    sole_lodestar(弱势群体应该怎么办) ,你的代码什么意思?com.document.*和com.util.*是哪里的包?
      

  4.   

    我没有源代码,只有编译之后的。你有源代码吗?给我一份,谢谢!
    我的信箱:[email protected]
      

  5.   

    很早以前做的一个,个人认为关键是    mySmartUpload.setContentDisposition(null);
        mySmartUpload.downloadFile(path,"application/msword",docName, 1024);
        out.close();
      

  6.   

    response.reset()在哪里调用?
        response.reset();
        mySmartUpload.initialize(pageContext);
        mySmartUpload.downloadFile(webname);
    这样写代码是不行的,还出现java.lang.IllegalStateException: getOutputStream() has already been called for this response
      

  7.   

    我这里有一份自己总结的SmartUpload的资料,已经mail给你了
      

  8.   

    guozhang,谢谢,你有源文件吗?
    你给的包还是出现异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
      

  9.   

    能不能把源文件也给我一份,谢谢了,[email protected]