错误 getWriter() has already been called for this response 的解决方法

HttpServletResponse在调用getWriter和getOutputStream两者之间之间只能选择一个,但有时已经调用过getOutputStream,仍然想调用getWriter,不难,用 java io 类嵌套一下就可以:

1     OutputStream out = null;
2     OutputStreamWriter ow = null; 
3    
4     out = resp.getOutputStream();
5     ow = new OutputStreamWriter(out);
6     ow.append("你想要添加的东西");    

 

posted @ 2017-09-06 16:35  glorythesky  阅读(2093)  评论(0编辑  收藏  举报