aspose file tools*
The moose likes JBoss/WildFly and the fly likes  Cannot forward after response has been committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark " Cannot forward after response has been committed" Watch " Cannot forward after response has been committed" New topic
Author

Cannot forward after response has been committed

raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
Hi to all,

i want to export some data to an excel file all when downloading the file it gives the following exception ...... after downloading the excel file i am trying to open it is saying like "the file you are trying to open .xls is in a different format than specified by the file extension"but data is not displaying in the file please any one help me how to solve this one.....


this is my error log...........

Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:417) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.1.0.Final]
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063) [:1.2.7]
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386) [:1.2.7]
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229) [:1.2.7]
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) [:1.2.7]
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [:1.2.7]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67) [:]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_13]





Thanks in advance suggest me....


[Thumbnail for screenshot.jpg]

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Have a look at a similar topic:
http://www.coderanch.com/t/422345/Servlets/java/response-setContentType-not-working-case
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
But it is not useful for me...

please suggest me any other suggestions...

Thanks
Pyla Rao
Ranch Hand

Joined: Jul 10, 2012
Posts: 50
The Java Illegal state exception states that you are attempting writing out put stream after response has been committed.
For solving this problem including return statement immediately after send redirect or forward statement.

raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
ya i have the return statement also..

but still the problem is not solved

suggest me with any other idea
Marcos R Oliveira
Ranch Hand

Joined: Apr 20, 2002
Posts: 51
Hi, raghu,

Could you please, post the code of your Filter class?

Marcos.


SCJP 1.4 - SCJP 1.6 - SCWCD in progress
shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 226

Check out weather your control is trying to go back from data-base to servlet. . . For execution of some more code in your servlet.
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
Hi here is my filter class code......
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
Hi to all,

i want to export some data to an excel file all when downloading the file it gives the following exception ...... after downloading the excel file i am trying to open it is saying like "the file you are trying to open .xls is in a different format than specified by the file extension"but data is not displaying in the file please any one help me how to solve this one.....


this is my error log...........

Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:417) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.1.0.Final]
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063) [:1.2.7]
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386) [:1.2.7]
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229) [:1.2.7]
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) [:1.2.7]
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [:1.2.7]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67) [:]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_13]

here is my jsp and action class codes---





Thanks in advance suggest me....
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
raghu tammina wrote:Hi to all,

i want to export some data to an excel file all when downloading the file it gives the following exception ...... after downloading the excel file i am trying to open it is saying like "the file you are trying to open .xls is in a different format than specified by the file extension"but data is not displaying in the file please any one help me how to solve this one.....


this is my error log...........

Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:417) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:407) [:6.1.0.Final]
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063) [:1.2.7]
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386) [:1.2.7]
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229) [:1.2.7]
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) [:1.2.7]
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [:1.2.7]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at com.zyom.security.LoginMonitorFilter.doFilter(LoginMonitorFilter.java:67) [:]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_13]

here is my jsp and action class codes---





Thanks in advance suggest me....
shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 226

First of all. .
Do not use so much import for import so many files from a package just use * it "ll make your code easy to read , understand and fast execution like

import java.io.*;

again i recomend you to check your servlet code. . Remember you can'nt dispatch any thing to jsp more than once. .
raghu tammina
Ranch Hand

Joined: Jul 11, 2012
Posts: 60
any one suggest me how to solve this.it is working in jboss 4.2.2 and it is not working in jboss 6.1

final java.io.OutputStream os = response.getOutputStream();

os.flush();

if above code is not added to my code it is giving the exception java.lang.IllegalStateException: getOutputStream() has already been called for this response.

any one please help me how to solve this issue?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

shivam singhal wrote:First of all. .
Do not use so much import for import so many files from a package just use * it "ll make your code easy to read , understand and fast execution like

import java.io.*;


Doing imports using * will not make your program (nor the compiler) run faster. Additionally, using makes it more difficult to determine which package each class came from, which will make the code harder to understand (yes an IDE will tell you the package name for each class but that does no good when you are looking at a printout). Finally, Eclipse and NetBeans will build and maintain the import lists for you so it makes no sense nowadays to use * for importing (well, maybe for Assert in JUnit...). So I recommend again using * imports.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot forward after response has been committed