• java.io.IOException: Stream closed 的问题



    public
    static String getBodyString(ServletRequest request) { StringBuilder sb = new StringBuilder(); InputStream inputStream = null; BufferedReader reader = null; InputStreamReader isr = null; try { inputStream = request.getInputStream(); isr = new InputStreamReader(inputStream, Charset.forName("UTF-8")); //reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); reader = new BufferedReader(isr); String line = ""; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } if (isr != null) { try { isr.close(); } catch (IOException e) { e.printStackTrace(); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return sb.toString(); }

    当普通请求进来没有处理字节流,所以流不存在关闭。

    当文件资源请求进来,会经过请求封装的流处理过程,流关闭后,在过滤器中被重复使用。报错!

    所以要对文件资源的请求做单独放行的处理。

  • 相关阅读:
    怎样绘制一个三角形边框
    怎样绘制一条线段
    怎样绘制矩形
    怎样判断浏览器是否支持canvas
    怎样创建一个canvas画布环境
    怎样理解Canvas
    怎样删除一条Cookie
    怎样在浏览器端增加一条Cookie
    怎样限制第三方Cookie
    怎样理解第三方Cookie
  • 原文地址:https://www.cnblogs.com/cat520/p/9300180.html
Copyright © 2020-2023  润新知