You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steven Banks <SD...@vac-acc.gc.ca> on 2002/06/20 15:15:53 UTC
Re: IllegalStateException: Cannot forward after response has
been committed
I was having the same problem on the os-390. Files being ftped to the mainframe were given file rights of 640. This made the web server unable to read the file. I fixed it by doing several things.
1. I moved the following lines to right before they were needed after the fileInputStream line"
response.setContentType("txt");
response.setHeader("Content-Disposition",
"attachment;filename=\"" + filename + "\";");
BufferedOutputStream bos = new
BufferedOutputStream(response.getOutputStream());"
This ensured that if an error occured when opening the input file, I could forward to an error page as a response file was not already open.
2. I also put in an additional check after the line
"File tmpFile = new File(filetoget);"
It was:
"
if ( ! tmpfile.canRead() ) {
return mapping.findForward("fail");
}
Steven Banks
368-0566
>>> "Thinh Doan" <th...@tds.net> 06/19/02 01:25AM >>>
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>