java.lang.IllegalStateException

根据servlet 3.0规范5.3节
"如果数据已经被写入response buffer,但还没有返回到客户端(比如response还没提交),则response buffer中的数据必须被清除并且由这些方法指定的数据代替.
 如果response已经被提交,则这些方法必须抛出IllegalStateException."

其中"这些方法"指的就是sendRedirect和sendError.
"这些方法指定的数据"指的是传递给sendRedirect或sendError的参数
out.close(); 会提交response, 所以再调用sendRedirect会出错

 

我所应用的是struts里面

PrintWriter pw = null;
  try {
   pw = ServletActionContext.getResponse().getWriter();
   pw.write(controlUnitobject.toString());
   System.out.println("size:"+ controlUnitDTOList.size());
   //pw.close();
  }catch (Exception e) {
    pw.write("0");
  }finally {
   if(null != pw){
    pw.close();
   }
  }

此处是通过PrintWriter 把json数据推送到前台

struts 的anction return一个String类型字符串,还得继续执行,所以报错,如果直接return null就可以了。


你可能感兴趣的:(java.lang.IllegalStateException)