struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thinh Doan" <td...@twjconsulting.com>
Subject IllegalStateException: Cannot forward after response has been committed
Date Wed, 19 Jun 2002 15:13:48 GMT
I have a download action that generates the above error upon return
mapping.findForward("success"). I did a search in the mail archive but
nothing seems to point to a solution.

Here is the code snippet of the download action:
...
        try {
            response.setContentType("txt");
            response.setHeader("Content-Disposition",
"attachment;filename=\"" + filename + "\";");

            BufferedOutputStream bos = new
BufferedOutputStream(response.getOutputStream());
            File tmpFile = new File(filetoget);
            FileInputStream fis = new FileInputStream(tmpFile);
            byte[] buffer = new byte[1024];
            int bytes_read;
            while((bytes_read = fis.read(buffer)) != -1) {
                bos.write(buffer, 0, bytes_read);
            }
            fis.close();
            bos.close();

            tmpFile.delete();

        } catch(FileNotFoundException fe) {
            return mapping.findForward("fail");
        } catch(IOException io) {
            return mapping.findForward("fail");
        }
        return ( mapping.findForward("success") );


Error in tomcat log:
...
2002-06-17 15:43:20 StandardWrapperValve[action]: Servlet.service() for
servlet action threw exception
java.lang.IllegalStateException: Cannot forward after response has been
committed
	at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatch
er.java:367)
	at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher
.java:355)
	at
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.ja
va:1759)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
...

Please indicate what I did wrong here. TIA for your help.

Thinh



--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message