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(); }
当普通请求进来没有处理字节流,所以流不存在关闭。
当文件资源请求进来,会经过请求封装的流处理过程,流关闭后,在过滤器中被重复使用。报错!
所以要对文件资源的请求做单独放行的处理。