ava.lang.IllegalStateException: getOutputStream() has already been called for this response

ぐ巨炮叔叔 提交于 2020-01-03 06:31:10

问题


    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:


Normally, it should allow calling response.getOutputStream() any number of times. I think you are calling both response.getOutputStream() and response.getWriter().

Please check if you are calling response.getWriter() anywhere or is the request is landing in JSP which writes to response.getWriter().



来源:https://stackoverflow.com/questions/10512179/ava-lang-illegalstateexception-getoutputstream-has-already-been-called-for-th

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!