Hello all,

I've searched around the forums attempting to discover a way to output a
file to the user.  What I'm trying to do is after creating a pdf file with
JasperReports i'd like to output it to the user.  I use Tapestry 4.02.  It
looks like the old way was to do something like this...

Make a method like the following a a listener, such as from a DirectLink or
whatever.

(The Document is just a class that holds the file information you want to
send to the user.)

public void downloadAction(IRequestCycle cycle)
{
   try
   {
       HttpServletResponse response =
       cycle.getRequestContext().getResponse();


       byte[] data = new byte[1024];
       FileInputStream in = document.getFileInputstream();


       response.setHeader("Content-disposition",
         "inline; filename=" +
          document.getFileName());
       response.setContentType(document.getMimeType());
       response.setContentLength(new Long(document.getSize()).intValue());
       ServletOutputStream out = response.getOutputStream();

       int bytesRead = 0;
       while ((bytesRead = in.read(data)) > -1)
       {
           out.write(data, 0 , bytesRead);
       }
       in.close();
       response.flushBuffer();
   }
   catch (IOException e)
   {
       e.printStackTrace();
   }
}

Now it output's a pdf file correctly, and everything seems to work
fine, but looking at the log, i get serveral of these:
javax.servlet.ServletException: getOutputStream() has already been
called for this response

Apparently the new correct way is to create a service.  Does anyone
have an example of outputing a file with a service?
Thank you very much for any assistance.

Reply via email to