我只是想在请求失败时将错误发送回客户端。这是我的代码:
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Email and username are required fields.");
此代码引发以下错误:
java.lang.IllegalStateException: null
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407) ~[catalina-6.0.26.jar:6.0.26]
at com.****.****.****.*********Servlet.service(********Servlet.java:68) ~[********Servlet.class:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ~[javaee-api-5.1.2.jar:5.1.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[catalina-6.0.26.jar:6.0.26]
at org.red5.logging.LoggerContextFilter.doFilter(LoggerContextFilter.java:78) ~[red5.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) [catalina-6.0.26.jar:6.0.26]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) [tomcat-coyote-6.0.26.jar:6.0.26]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) [tomcat-coyote-6.0.26.jar:6.0.26]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote-6.0.26.jar:6.0.26]
为什么把这扔在这里?在此调用之前,我没有做任何与响应对象有任何关系的操作,直到在if子句中发送此错误之前,我什至没有触摸它。为什么会出现此错误?
最佳答案
HttpServletResponse(由ResponseFacade实现)引发IllegalStateException的唯一原因是响应之前已经提交过。它一定已经被某人触摸过。
关于java - IllegalStateException:HttpServlet.service中为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11215014/