Hassan Schroeder wrote:
On Thu, Sep 25, 2014 at 7:18 AM, Léa Massiot <lmhe...@orange.fr> wrote:

I was thinking maybe about an "error-page"... (never done that before): in
case an exception is thrown after the response "has been committed", maybe
this error page could be sent to the user...

Since the user's browser will still be displaying "download-file.jsp"
after the download, why not add some JS/AJAX to the page to poll
for a status update and display that?

Just another possibility :-)


+1, yes, something like that.

Lea, the problem is that what you want to achieve, goes against the very logic of the standard HTTP protocol. In HTTP, the client sends one request, and expects one response for that request; and the server receives one request, and sens one response. The server *can not* send a second response for that same request; and if it did, the client would not know what to do with it.

So in your case, the client sends a request to get one file; and it expects in return that file, not more, not less. If you try to send something else in addition to (or instead of) the file, then the client is going to get very confused, and either see this as an error, or it will save or display a corrupted file.

And another thing : if the server at some point notices an error while sending the response (the file), in 99.95% of the cases this will be because the connection with the client has been lost, and Tomcat can not write any more data on that connection. So whatever you would try to send as an error message or page, has nowhere to go, and your webapp would get an I/O exception.

If you really want to do something like this, then you need a "collaboration" between the server and the client. For example, something like the above suggestion : when the client clicks on the link to downoad the file, this does not send a request to the server directly from the HTML page. Instead, it triggers some javascript function (AJAX-like) which is the one that will send the request to the server, and receive the file. And then, if at some point there is a problem in that download, the javascript function can inform the user, by writing a message into the original browser window which is displayed to the user, and which originated the javascript call. But this is not as easy to do as you might think, because this javascript may not have the permission to write to the user workstation disk, to save the received file (security). So you may need a java applet instead, and signed, so that the user can give it the required permissions.

So you see what you are getting into. It is certainly do-able, but do you want to go through the effort of doing that ?
(and if you do, then search Google for "jquery").

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

Reply via email to