A little new to GWT here but I've searched around and not found any
obvious help to my problem:
I have a servlet that handles GET requests for a file, which it sends
back on the httpResponse through the PrintWriter.
To test, if I put a link on a page which fires to this servlet, the
browser responds with the standard "Save to" dialog box and then
downloads the file. The file is properly saved to my client machine.
All good so far.
However, if instead I use the RequestBuilder with a RequestCallback to
fire a GET request to the servlet instead of just a simple link
(anchor), everything works fine (servlet code is hit, stepping through
it seems fine and the response on the client side looks correct)
except I don't get the "Save to" dialog. If I look at the 'text' of
the response it *is* the contents of the file, the headers look
correct, etc.
My guess is that I'm basically overriding the browser's handler that
would normally see the response and throw up the dialog with this
RequestCallBack. But I don't see anyway of not overriding it.
Not sure if I've given enough details here for anyone to understand my
issue, so please let me know what more would help.
Thanks in advance,
Will
These are AJAX calls - XmlHttpRequests. They would NEVER pop up a
browser dialog. They are expressly used for javascript software to
download data from a server into a format they can use internally. The
behaviour you are seeing is both correct and the only thing it'll ever
do.
The only way to do what you want is to create some sort of <a href> in
your app, using e.g. a HTML widget. It helps to target="_blank", but
at this point we're no longer talking GWT, I suggest you google for
some tutorials on how to construct links so that they always download
(I believe it's primarily a function of what Content-Type header your
server sends).