在写一个ssh项目时,遇到一个之前从没遇到过的问题,抛出的异常如下
一月 06, 2017 5:01:40 下午 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/AnyviewSystem] threw exception
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:462)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:834)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
hibernate产生的sql语句如下
Hibernate:
select
count(*) as y0_
from
anyviewdb.Class_CourseTable this_
inner join
anyviewdb.CourseTable course1_
on this_.CourseID=course1_.CourseID
where
this_.CID=?
order by
this_.StartYear asc
[http-nio-8080-exec-11] (HibernateTemplate.java:435) - Not closing pre-bound Hibernate Session after HibernateTemplate
[http-nio-8080-exec-11] (HibernateTemplate.java:410) - Found thread-bound Session for HibernateTemplate
Hibernate:
select
this_.ID as ID8_7_,
this_.CID as CID8_7_,
this_.CourseID as CourseID8_7_,
this_.StartYear as StartYear8_7_,
this_.status as status8_7_,
this_.TID as TID8_7_,
this_.UPDATETIME as UPDATETIME8_7_,
classtable3_.CID as CID1_0_,
classtable3_.CNAME as CNAME1_0_,
classtable3_.CEID as CEID1_0_,
classtable3_.CreateTime as CreateTime1_0_,
classtable3_.ENABLED as ENABLED1_0_,
classtable3_.EPID as EPID1_0_,
classtable3_.KIND as KIND1_0_,
classtable3_.SPECIALTY as SPECIALTY1_0_,
classtable3_.STARTYEAR as STARTYEAR1_0_,
classtable3_.STATUS as STATUS1_0_,
classtable3_.UPDATETIME as UPDATETIME1_0_,
collegetab4_.CEID as CEID4_1_,
collegetab4_.CENAME as CENAME4_1_,
collegetab4_.CreateTime as CreateTime4_1_,
collegetab4_.ENABLED as ENABLED4_1_,
collegetab4_.UNID as UNID4_1_,
collegetab4_.UPDATETIME as UPDATETIME4_1_,
course1_.CourseID as CourseID12_2_,
course1_.Category as Category12_2_,
course1_.CEID as CEID12_2_,
course1_.CourseName as CourseName12_2_,
course1_.CreateTime as CreateTime12_2_,
course1_.Enabled as Enabled12_2_,
course1_.UNID as UNID12_2_,
course1_.UPDATETIME as UPDATETIME12_2_,
collegetab6_.CEID as CEID4_3_,
collegetab6_.CENAME as CENAME4_3_,
collegetab6_.CreateTime as CreateTime4_3_,
collegetab6_.ENABLED as ENABLED4_3_,
collegetab6_.UNID as UNID4_3_,
collegetab6_.UPDATETIME as UPDATETIME4_3_,
university7_.UNID as UNID5_4_,
university7_.ATTR as ATTR5_4_,
university7_.CreateTime as CreateTime5_4_,
university7_.ENABLED as ENABLED5_4_,
university7_.IP as IP5_4_,
university7_.PORT as PORT5_4_,
university7_.UNNAME as UNNAME5_4_,
university7_.UPDATETIME as UPDATETIME5_4_,
university7_.VERIFICATION as VERIFICA9_5_4_,
teachertab8_.TID as TID0_5_,
teachertab8_.CreateTime as CreateTime0_5_,
teachertab8_.ENABLED as ENABLED0_5_,
teachertab8_.TCID as TCID0_5_,
teachertab8_.TNAME as TNAME0_5_,
teachertab8_.TNO as TNO0_5_,
teachertab8_.TPSW as TPSW0_5_,
teachertab8_.TSID as TSID0_5_,
teachertab8_.TSEX as TSEX0_5_,
teachertab8_.UNID as UNID0_5_,
teachertab8_.UPDATETIME as UPDATETIME0_5_,
university9_.UNID as UNID5_6_,
university9_.ATTR as ATTR5_6_,
university9_.CreateTime as CreateTime5_6_,
university9_.ENABLED as ENABLED5_6_,
university9_.IP as IP5_6_,
university9_.PORT as PORT5_6_,
university9_.UNNAME as UNNAME5_6_,
university9_.UPDATETIME as UPDATETIME5_6_,
university9_.VERIFICATION as VERIFICA9_5_6_
from
anyviewdb.Class_CourseTable this_
left outer join
anyviewdb.ClassTable classtable3_
on this_.CID=classtable3_.CID
left outer join
anyviewdb.CollegeTable collegetab4_
on classtable3_.CEID=collegetab4_.CEID
inner join
anyviewdb.CourseTable course1_
on this_.CourseID=course1_.CourseID
left outer join
anyviewdb.CollegeTable collegetab6_
on course1_.CEID=collegetab6_.CEID
left outer join
anyviewdb.UniversityTable university7_
on course1_.UNID=university7_.UNID
left outer join
anyviewdb.TeacherTable teachertab8_
on this_.TID=teachertab8_.TID
left outer join
anyviewdb.UniversityTable university9_
on teachertab8_.UNID=university9_.UNID
where
this_.CID=?
order by
this_.StartYear asc limit ?
对于这个问题,我在stackoverflow中看到一个解释:
原文链接如下http://stackoverflow.com/questions/20813496/tomcat-exception-cannot-call-senderror-after-the-response-has-been-committed
This error is a symptom of some other problem, not the root cause you're looking for.
This error explains why the user can't be redirected to the error page. (Reason: the server has already flushed part of the response buffer back to the client - it's too late to switch/redirect to the error page.)
As the error message points out, check elsewhere in your Apache Tomcat 7 logs (or debug your app another way) to find what is throwing an exception.
翻译如下:
这个错误是其他问题的一个征兆,而不是你要找的根本原因.。
此错误解释了为什么用户不能重定向到错误页.。(原因:服务器已经将响应缓冲区的一部分刷新到客户端了,切换到错误页面已经太晚了。)
正如错误消息指出那样,在你的Apache Tomcat 7日志中(或调试你的应用程序)看看到底是什么导致抛出这个异常。
看了很多地方,肯定代码一定没有问题,那只能是是数据库的问题,然后把hibernate生成的sql语句放入数据库中运行,果然出现问题。显示数据库中没有ID这个字段,查看数据库结果,果然没有ID这个字段
原来是数据库文档更新了,但数据库结构没有跟着更新导致的
[Err] 1054 - Unknown column 'this_.ID' in 'field list'
出现这个异常,首先看看自己的数据库是否有问题。找这个bug花了一整个下午,希望对大家有用。