`

java.lang.IllegalStateException:

 
阅读更多
1,错误现象
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2390)
at org.apache.catalina.connector.Request.getSession(Request.java:2110)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:547)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:493)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:224)
2,错误分析
List<Directory> list = new ArrayList<Directory>();
list = directoryService.queryDirectory();
PrintWriter pw = ServletActionContext.getResponse().getWriter();

                   pw.print(list);
  pw.close();
之所以会出现此类问题是因为我们在Response输出响应后才创建Session的。
(因为那时候服务器已经将数据发送到客户端了,即:就无法发送Session ID 了)

3,错误解决方法
List<Directory> list = new ArrayList<Directory>();
PrintWriter pw = ServletActionContext.getResponse().getWriter();
                  list = directoryService.queryDirectory();
pw.print(list);
pw.close();
上述位置互换
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics