当我尝试在EXCEL中保存JSP数据时,我从Tomcat服务器收到IllegalStateException。 IllegalStateException
可能出现以下任何一种情况:
sendRedirect()
之后没有退货声明。除此之外,IllegalStateException
是否有任何原因?
我的代码:
response.sendRedirect(response.encodeRedirectURL(request.getRequestURI() + "?saveToFile=true&action=" + ReportsManager.ACTION_SAVE_AS_XLS + "&saveFileName=" + saveFileName + "&returnPage=" + StringFunctions.encodeUrlParameter(returnPage)));
return;
我在sendRedirect()获得IllegalStateException
。
此外,如果JSP中只有少量记录(比如说100行),则保存为Excel时不会出错。如果有1000条记录,那么我将获得IllegalStateException
。
堆栈追踪:
*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)
如果我设置了页面缓冲区大小,那么它可以完成1000条记录。但是如果它达到了2000条记录,那么我又会遇到问题。
<%@ page buffer = "2048kb" autoFlush = "true" %>
答案 0 :(得分:3)
sendRedirect 抛出:IllegalStateException - 如果此响应已提交
由于禁用maxPostSize并不能解决问题(根据OP注释),似乎在较早的时候响应正在提交。
您可以通过查看isCommited标记验证这一点。
答案 1 :(得分:2)
如果你调用两次“response.sendRedirect()”方法, 或url是一个错误的网址,此错误可能会导致
答案 2 :(得分:0)
在不同的用例中遇到相同的错误。
用例:在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());
关键点