在 servlet 类的 doPost 方法中执行此操作时,在 PrintWriter 上获取 IOExcepiton:
doPost(HttpServletRequest request,
HttpServletResponse response){
String replyMessage = "STATUS_ACCEPT";
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/plain; charset=utf-8");
response.setContentLength(replyMessage.length());
response.setIntHeader("content-length", replyMessage.length());
response.getWriter().println(replyMessage);//getting IOException closed on calling this method
response.flushBuffer();}
如果我使用输出流发送数据没有错误:
ServletOutputStream outputStream = response.getOutputStream();
byte[] result = "STATUS_ACCEPT".getBytes("UTF-8");
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/plain; charset=utf-8");
response.setContentLength(result.length);
response.setIntHeader("content-length", result.length);
outputStream.write(httpOutData);
我应该如何使用 printwriter 没有得到 IOException?