【问题标题】:ava.lang.IllegalStateException: getOutputStream() has already been called for this responseava.lang.IllegalStateException: getOutputStream() 已经为此响应调用
【发布时间】:2012-05-09 08:07:58
【问题描述】:
    String contenttype = rs.getString("contentType");
    String filename = rs.getString("fileName");

    response.setContentType(contenttype);
    response.setHeader("Content-disposition","attachment;filename=" + filename.replace('"', ' '));


    java.io.InputStream instream = rs.getBinaryStream("fileData");
    byte[] b = new byte[1000];
    while (instream.read(b) > 0) {
        try {
            response.getOutputStream().write(b);
        }
        catch(Exception e) {}
    }

    try {
        response.getOutputStream().flush();
    }
    catch(Exception e) {}

【问题讨论】:

  • 尝试将 response.getOutputStream() 提取到一个局部变量并在循环和刷新时使用该变量

标签: jsp servlets


【解决方案1】:

通常,它应该允许调用response.getOutputStream() 任意次数。我想你同时打电话给response.getOutputStream()response.getWriter()

请检查您是否在任何地方调用response.getWriter(),或者请求是否在写入response.getWriter() 的JSP 中登陆。

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2020-01-08
    • 2012-12-14
    • 2016-03-03
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多