Did you return null? Since u write as pdf, you can only return null as forward.
Regards, Phillip Qin "This Guy Thinks He Knows Everything" -----Original Message----- From: Srinivas Sampige [mailto:[EMAIL PROTECTED]] Sent: December 27, 2002 7:34 PM To: Struts Users Mailing List Subject: RE: problem streaming file to browser Hi Thanks for your reply.The code you have supplied is on the lines of what I am doing. Here is what happens. First time the action is run the PDF comes out fine to the nrowser but with this message on the server side - 2002-12-27 15:39:46 - Ctx( /etrac ): IllegalStateException in: R( /etrac + /reportAction.do + null) Cannot forward as OutputStream or Writer has already been obtained Then I cannot generate the PDF again until I execute another action by say ... doing back to the main menu of my web app(through another action) OR say by logging out. I get the same "IllegalStateException" error in another simple test Action that I put together. Can somebody help me? The same thing works fine in as servlet. So, I am not able to understand what is special about a Struts Action! Should I be doing something else?. Here are snippets of my code- public abstract class EtracAction extends EtacAction { public ActionForward perform(ActionMapping mapping,ActionForm form ,HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { .... .... return performAction(mapping, form, request, response,userSessionInfo); } public abstract ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserSessionInfo userSessionInfo) throws IOException, ServletException; }//end of EtracAction ----------------------------------------------- ReportAction extends EtracAction { public org.apache.struts.action.ActionForward performAction (org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, UserSessionInfo userSessionInfo) throws javax.servlet.ServletException, java.io.IOException { byte[] reportBuffer = reportManager.generateReport(userSessionInfo); String fileName = ""; //write the pdf to the response if (reportBuffer != null) { response.setContentType("application/pdf"); response.setHeader("Window-target","report_window"); fileName = "etracPdfReport.pdf"; ServletOutputStream sout = response.getOutputStream(); //THIS IS THE CODE THAT FAILS THE SECOND TIME AROUND,HAVE TO EXECUTE ANOTHER ACTION BEFORE ANOTHER PDF CAN BE STREAMED BACK TO BROWSER. sout.write(reportBuffer); //sout.flush(); //tried these two lines to avoid above error //sout.close(); //but no improvement. } return mapping.findForward(Forwards.REPORT_PAGE); }//end of performaction }//end of ReportAction thanks in advance Srinivas >===== Original Message From "Struts Users Mailing List" <[EMAIL PROTECTED]> ===== >stmt is an Oracle BFILE > > InputStream in = null ; > BufferedInputStream bis = null ; > ServletOutputStream writer = null ; > > try > { > stmt.openFile() ; > in = stmt.getBinaryStream() ; > bis = new BufferedInputStream(in) ; > int length ; > byte[] buf = new byte[512] ; > writer = response.getOutputStream() ; > response.setContentType("application/pdf") ; > while ((length=bis.read(buf))!= -1) > { > writer.write(buf) ; > } > } > finally > { > if (writer != null) > writer.close() ; > if (in != null) > in.close() ; > if (bis != null) > bis.close() ; > if (stmt != null) > stmt.closeFile() ; > } > >Regards, > > >Phillip Qin > >"This Guy Thinks He Knows Everything" > > >-----Original Message----- >From: Srinivas Sampige [mailto:[EMAIL PROTECTED]] >Sent: December 27, 2002 2:39 PM >To: [EMAIL PROTECTED] >Subject: problem streaming file to browser > >Hi > I havene an action in which I am streaming a PDF file to the browser. I am >doing that by doing a response.getOutputStream() in the action and writing >to >the resulting ServletOutputStream. The first time it works fine, the PDF >appears on the browser but with an illegal state exception on the console on > >the server side. The next time the user chooses to download a file and the >same action is run again I get an error saying that the the servlet output >stream has already been obtained and the PDF does not appear. The user has >to >log out of the web application and then log back on for the PDF download to >work. Could anybody give me an idea what is going wrong? What is the best >way >to code this functionality? Could somebody provide OR point me to some >source >code? > >thanks >Srinivas > > >-- >To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> ------------------------------------------------------------ Get your FREE web-based e-mail and newsgroup access at: http://MailAndNews.com Create a new mailbox, or access your existing IMAP4 or POP3 mailbox from anywhere with just a web browser. ------------------------------------------------------------ -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>