Re: File Download with multiple files. Design question

2010-11-20 Thread Paweł Wielgus
Hi All,
read about streamResult (I assume You use struts2), and also there is
no need for next action in chain, user can simply check as many files
as he wants and click download what will call downloadAction that will
simply return zip file for download, after downoading user is still at
the same page.

Best greetings,
Pawel Wielgus.



2010/11/19 RogerV roger.var...@googlemail.com:



 Li Ying wrote:

 My suggestion:

 (1)I believe you can use ZipOutputStream to output the zipped data to
 the response OutputStream directly, instead of a temp file. So no temp
 file need to be created.


 Hmm, write to the response.outputStream directly from within my action? That
 would work I guess. Any examples of doing this in struts 2 and how to
 navigate to the next display after the download?

 In this instance the first option would be best as I don't need the temp
 file, it was my first solution to providing the StreamResult with an input
 stream that would download multiple files.

 Regards

 --
 View this message in context: 
 http://old.nabble.com/File-Download-with-multiple-files.-Design-question-tp30256036p30258354.html
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: File Download with multiple files. Design question

2010-11-20 Thread Li Ying
 Any examples of doing this in struts 2

You can get the HttpServletResponse by:
   ServletActionContext.getResponse()

And then, you can set the download file name, by:
   response.setHeader(Content-Disposition,
attachment; filename= + fileName);

And then, you can get the OutputStream, by:
  response.getOutputStream()

Finally, you can output zipped data to the OutputStream.



 how to navigate to the next display after the download?

I believe you can not navigate to the next page.
Because for one http request, the server side can send only one response.
If you want to download file and then show next page, it need 2 responses.
I think this is impossible mission for one http request.

If you send a file download response, then the browser will download
it, and don't refresh the page, which means the current displayed page
will remain.

If you really want to implement this, may be you need some client side
JavaScript to send a file download request first, and then send
another request to display the next page.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: File Download with multiple files. Design question

2010-11-20 Thread Roger Varley
On Sat, 2010-11-20 at 09:41 +0100, Paweł Wielgus wrote:
 Hi All,
 read about streamResult (I assume You use struts2), and also there is
 no need for next action in chain, user can simply check as many files
 as he wants and click download what will call downloadAction that will
 simply return zip file for download, after downoading user is still at
 the same page.
 
Hi Pawel

That's what I'm doing, but the StreamResult requires an InputStream
which forces the intermediate step of creating a temporary file and it's
the issue of how to clean up the temporary file (knowing when the
StreamResult has completed) that's causing the issue.

Li's suggestion of writing directly to the response.getOutputStream()
would work, but it means my action now has to know about the servlet api
and will be awkward to test.

A third alternative I was considering was something like;

public class DeleteOnCloseFileInputStream extends FileInputStream {

File file;

public DeleteOnCloseFileInputStream(File file) {
super(file);
this.file = file;
}
@Override
public void close() {
super.close();
file.delete();
}

}

and passing that to the StreamResult.

Regards


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org