Hi all
I'm experiencing a problem while implementing a download servlet; I'm
not sure what's the nature of the problem, but since it appears
withing a GWT/GAE application, I'm firstly posting it here. Please,
let me know if this not the right place.
I'm developing an application under Mac OS 10.5. In hosted mode (the
only I can run now), the user produces some data on the client side,
and then he has the possibility to save locally the data according to
a file format. To do this, the data is jsonized and sent to an
HttpServlet. The servlet de-jsonizes the data, writes it to some xml
files, stores the files into a ZipOutputStream and writes the zip to
the response output. The header content type of the response is then
set as "attachment" and sent back.
The symptom of the problem is that on the client side the response is
received but the browser (Firefox) does not display the "save as".
Here is the smallest non-working server-side code (without zip/xml
concerns):
protected void doPost( HttpServletRequest req, HttpServletResponse
resp )
throws ServletException, IOException
{
ServletOutputStream out = resp.getOutputStream();
resp.setContentType( "application/download" );
resp.setHeader("Content-Disposition",
"attachment;filename=output.bin");
out.println( "Test" );
resp.setContentLength( 4 );
}
And here is the client-side:
void loadHttpServlet()
{
String url = GWT.getHostPageBaseURL() + "saveProjectLocally";
RequestBuilder builder = new RequestBuilder(
RequestBuilder.POST,
url );
try
{
builder.sendRequest( getJSONdata(), new
RequestCallback() {
public void onError( Request request, Throwable
exception )
{
}
public void onResponseReceived( Request request,
Response response )
{
{
// Window.alert(
response.getStatusCode() + " - " +
response.getText() );
}
}
} );
}
catch( Exception e )
{
Window.alert( e.getMessage() );
}
}
Notice that:
- response.getText() successfully reports "Test"
- in Firebug, "net" panel, after the request has completed, if I right-
click and select "Open Response in New Tab", the "Save as" box appears
and a file with random name (e.g., +hA6gF9P(2).part) is saved with the
right content.
I have googled a lot, both on the web and on this forum, to find a
solution but I didn't find anything matching my problem.
Any idea?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.