如何解决Servelts中的非法状态异常

时间:2018-03-16 11:02:35

标签: java jsp servlets

异常追踪:

  

"" java.lang.IllegalStateException:响应后无法转发   一直致力于           在org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328)           在org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)           在com.zoho.campaign.client.filters.CampaignDomainFilter.doFilter(CampaignDomainFilter.java:140)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在com.zoho.campaign.client.filters.CampaignDefaultFilter.doFilter(CampaignDefaultFilter.java:165)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在com.adventnet.iam.security.SecurityFilter.doFilter(SecurityFilter.java:217)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在com.adventnet.zoho.crmplus.agent.filter.CRMPlusFilter.doFilter(CRMPlusFilter.java:55)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在com.zoho.logs.logclient.filter.AccessLogFilter.doFilter(AccessLogFilter.java:61)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在com.zoho.instrument.InstrumentFilter.doFilter(InstrumentFilter.java:37)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)           在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)           在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)           在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)           在org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:480)           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)           在org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:240)           在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)           在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)           在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)           at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:672)           在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1520)           在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1476)           在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)           at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)           at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)           在java.lang.Thread.run(Thread.java:745)

尝试转发RequestDispatcher时获取此异常

出现此问题的原因是什么?

代码:

public void doFilter(ServletRequest req,ServleResponse res,FilterChain filterchain)thorws IOException,Exception
{
String downloaurl="expired";
boolean is_allow_download=false;
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)res;
RequestDispatcher rd=null;
if(downloadurl.equals("expired"))
    {
    request.setAttribute("isexpire", "expire");
  }
  else if(downloadurl.equals("no_data"))
     {
       request.setAttribute("isdataAval", false);
  }
     if(url1.contains("export.do") && !downloadurl.equals("no_data") && is_allow_download )
       {
         rdc = request.getRequestDispatcher("users/export.do");
         rdc.forward(request, response);
       }
      rdc = request.getRequestDispatcher("users/closed.do"); 
        rdc.forward(request, response);

}

1 个答案:

答案 0 :(得分:0)

假设您的堆栈跟踪,您的RS已在您尝试调用forward()方法之前已提交。您的申请已提前退回RS。

P.S。请添加一些代码段以获取更多上下文。