当我尝试将JSP的数据保存在EXCEL中时,我从Tomcat服务器获取了IllegalStateException。 IllegalStateException
可能在以下任一情况下发生:sendRedirect()
之后是否没有return语句。
如果POST大小大于2MB。
如果页面缓冲区大小较小。
除此之外,是否有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" %>
最佳答案
Documentation指出:
sendRedirect抛出:IllegalStateException-如果已经提交了此响应
由于禁用maxPostSize不能解决问题(根据OP注释),因此似乎响应是在早期提交的。
您可以通过检查isCommited标志来验证这一点。
关于java - IllegalStateException的原因,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15609033/