ava.lang.IllegalStateException:已为此响应调用了getOutputStream()

时间:2012-05-09 08:07:58

标签: jsp servlets

    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) {}

1 个答案:

答案 0 :(得分:0)

通常情况下,它应该允许多次调用response.getOutputStream()。我认为您同时呼叫response.getOutputStream()response.getWriter()

请检查您是否在任何地方呼叫response.getWriter(),或者请求是否已在JSP中登录,并写入response.getWriter()