Yes, you cannot do it with ajax, you must use a link with the src
pointing to a hidden iframe or a new window.

Take a look to how it is done in Hupa (Apache-James webmail)

- Server side (line 100):
http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java?view=markup

- Client side code (line 142)
http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java?view=markup

- Html page
http://svn.apache.org/viewvc/james/hupa/trunk/client/war/Hupa.html?view=markup

Cheers
Manolo

On Sun, Apr 11, 2010 at 12:02 PM, Thomas Broyer <[email protected]> wrote:
>
>
> On Apr 10, 5:02 pm, daaSdemahoM <[email protected]> wrote:
>> Hi,
>>
>> im trying to create a web app thats allow me to download a file
>> generated from server (not stored).
>> on server side:
>> ich have implemented a download servlet below:
>> public void doGet(HttpServletRequest request, HttpServletResponse
>> response)
>>       throws ServletException, IOException {
>>
>>     ServletOutputStream servletOStream = null;
>>     ByteArrayOutputStream baOPStream = null;
>>     try {
>>       baOPStream = //generated file as stream
>>       if (baOPStream != null) {
>>
>>         StringBuffer sbFilename = new StringBuffer();
>>         sbFilename.append("MSP_");
>>         sbFilename.append(System.currentTimeMillis());
>>         sbFilename.append(".ppt");
>>
>>         response.setContentLength((int) baOPStream.size());
>>         response.setContentType("application/octet-stream");
>>         response.setHeader("content-disposition", "attachment;
>> filename=\""
>>             + sbFilename + "\"");
>>
>>         servletOStream = response.getOutputStream();
>>         servletOStream.write(baOPStream.toByteArray());
>>         servletOStream.flush();
>>       }
>>     } catch (IOException ioe) {
>>       throw new ServletException(ioe.getMessage());
>>     } finally {
>>       servletOStream.close();
>>       baOPStream.close();
>>     }
>>
>>   }
>>
>>   public void doPost(HttpServletRequest request, HttpServletResponse
>> response)
>>       throws ServletException, IOException {
>>     doGet(request, response);
>>   }
>>
>> on the client side i used a Requestbuilder to send a string to the
>> server as follow:
>>
>> RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "/
>> procedmsp/download");
>> ExportRequestHandler exportHandler = new ExportRequestHandler(){
>>    public void onError(Request req, Throwable exception) {
>>      //error handling
>>    }
>>    public void onResponseReceived(Request req, Response resp) {
>>     //.....get the response and start the download????
>>    }};
>>
>>  builder.setCallback(exportHandler);
>>  builder.setRequestData(data); //String data to send
>>  builder.send();
>>
>> the question is. i dont know how to start the file download. any idee?
>
> You can't trigger a download with RequestBuilder (or anything based on
> XMLHttpRequest), you have to use a link (Anchor widget) or form
> (FormPanel widget).
>
> --
> 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.
>
>

-- 
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.

Reply via email to