简体   繁体   English

IllegalStateException 的原因

[英]Causes for IllegalStateException

I'm getting IllegalStateException from Tomcat server, when I try to save a JSP's data in EXCEL.当我尝试在 EXCEL 中保存 JSP 的数据时,我从 Tomcat 服务器收到 IllegalStateException。 IllegalStateException can occur in any of the following condition: IllegalStateException可能发生在以下任何一种情况下:

  • If there is no return statement after sendRedirect() .如果sendRedirect()之后没有 return 语句。
  • If POST size is greater than 2MB.如果 POST 大小大于 2MB。
  • If page buffer size is less.如果页面缓冲区大小较小。

Other than this, is there any causes for IllegalStateException ?除此之外,是否有导致IllegalStateException任何原因?

My code:我的代码:

response.sendRedirect(response.encodeRedirectURL(request.getRequestURI() + "?saveToFile=true&action=" + ReportsManager.ACTION_SAVE_AS_XLS + "&saveFileName=" + saveFileName + "&returnPage=" + StringFunctions.encodeUrlParameter(returnPage)));    
return;

I'm getting IllegalStateException at sendRedirect().我在 sendRedirect() 处收到IllegalStateException

Also if there are only few records (say 100 rows) in JSP, then there is no error in saving as Excel.此外,如果 JSP 中只有很少的记录(比如 100 行),那么保存为 Excel 没有错误。 If there is 1000 records, then I'm getting IllegalStateException .如果有 1000 条记录,那么我会收到IllegalStateException

Stack trace:堆栈跟踪:

*Mar 25, 2013 6:57:26 AM,JSP Runtime Error,0,java.lang.IllegalStateException
       at org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:352)
       at org.apache.jsp.OperationalReports.SalespersonSales_jsp._jspService(SalespersonSales_jsp.java:2567)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
       at com.retailJava.core.filters.SecurityFilter.doFilter(SecurityFilter.java:136)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
       at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
       at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
       at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
       at java.lang.Thread.run(Thread.java:595)

If I set page buffer size, then it worlks fine for 1000 records.如果我设置页面缓冲区大小,那么它可以正常处理 1000 条记录。 But if it reaches 2000 records, then again I'm getting issue.但是如果它达到 2000 条记录,那么我又遇到了问题。

<%@ page buffer = "2048kb" autoFlush = "true" %>

The Documentation states: 文档指出:

sendRedirect Throws: IllegalStateException - if this response has already been committed sendRedirect抛出:IllegalStateException - 如果此响应已提交

Since disabling the maxPostSize does not solve the problem (according to OP comments) it seems that at an earlier point the responce is beeing commited.由于禁用 maxPostSize 并不能解决问题(根据 OP 评论),似乎在更早的时候响应正在提交。

You can verify this by checking the isCommited flag.您可以通过检查isCommited标志来验证这一点。

如果你调用两次“response.sendRedirect()”方法,或者url是一个错误的url,这个错误可能会导致

Encounter the same error in different use case.在不同的用例中遇到相同的错误。

在此处输入图片说明

Use Case : In Hibernate, when we try to access any method on session object after closing the session intentionally.用例:在 Hibernate 中,当我们有意关闭会话后尝试访问会话对象上的任何方法时。

Session session = /*Getting session object using factory*/
tx = session.beginTransaction();
System.out.println("Flush Mode before closing session -> " +session.getFlushMode());

session.close();
System.out.println("Flush Mode after closing session -> " + session.getFlushMode());

Key Point关键

  • IllegalStateException occur due to method invocation at in appropriate time由于在适当的时间调用方法而发生 IllegalStateException
  • In context of session, we can't call any method of session once it is closed在 session 上下文中,一旦关闭,我们就不能调用 session 的任何方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android:onClick =“”导致IllegalStateException - android:onClick=“” causes IllegalStateException AdWhirl导致IllegalStateException - AdWhirl causes IllegalStateException Apache POI:更改CellType导致IllegalStateException - Apache POI: changing CellType causes IllegalStateException 从Java导出的Primefaces导致IllegalStateException - Primefaces Export from Java causes IllegalStateException 带有BindingResult的@Valid JSON请求会导致IllegalStateException - @Valid JSON request with BindingResult causes IllegalStateException @PostConstruct中抛出的异常会导致JSF 2.1中出现IllegalStateException - Exception thrown in @PostConstruct causes IllegalStateException in JSF 2.1 android DialogFragment android:onClick =“ buttonCancel”导致IllegalStateException找不到方法 - android DialogFragment android:onClick=“buttonCancel” causes IllegalStateException could not find a method request.getSession(false) 导致 java.lang.IllegalStateException - request.getSession(false) causes java.lang.IllegalStateException 在 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 上调用 forEach 会导致 java.lang.IllegalStateException - Calling forEach on a stream causes java.lang.IllegalStateException 使用JavaFX的多线程导致java.lang.IllegalStateException:不在FX应用程序线程上 - Multithreading with JavaFX causes java.lang.IllegalStateException: Not on FX application thread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM