`
chimae
  • 浏览: 25342 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Why do I get java.lang.IllegalStateException?

阅读更多
Why do I get java.lang.IllegalStateException?
These are the most common reasons how you can get an java.lang.IllegalStateException:
  • Calling setBufferSize and content has been written.
  • The response has been committed and you do any of the following:
    • Calling ServletResponse.reset() or ServletResponse.resetBuffer()
    • Calling either HttpServletResponse.sendError() or HttpServletResponse.sendRedirect().
    • Calling RequestDispatcher.forward() which includes performing a jsp:forward
    • Calling RequestDispatcher.forward() which includes performing a jsp:forward
Remember that if you call forward() or sendRedirect(), any following lines of code will still execute. For example:
{  ...  response.sendRedirect("foo.jsp");  // At this point, you should probably have a return statement otherwise  // the following code will run  System.out.println("After redirect! By the way ...");  System.out.println("Use commons-logging or log4j, not System.out");  System.out.println("System.out is a bad practice!");  response.sendRedirect("bar.jsp"); /* This will throw an error! */}    


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics