Ilan Azbel <[EMAIL PROTECTED]> wrote:
> I would like a vm to return a binary file and thereby instruct the browser
> not to display it, but rather to download it. That is, ask the user if 
they
> would like to "Open" or "Save" the file.
> 
> I would like to do this without any redirecting statements - so as soon as 
a
> user requests a certain .vm file, the corresponding java creates some type
> of binary data, and the browser immediately asks whether to open or save
> this data.

Ilan,

Both your requests to create a csv and a binary file for download are 
generally outside of the scope of velocity servlets.

You'd generally do this using a different servlet.

What servlet framework are you using?

For example, in struts, you'd do something like this in an action to create 
a pdf file to download.
To create another file type (cvs, binary), you'd simply change the content 
type and provide a different file generator.

        response.setContentType("application/pdf");

        ByteArrayOutputStream memoryOutputStream = new 
ByteArrayOutputStream();

        BillPdfer billPdfer = new BillPdfer(selectedBill, 
memoryOutputStream);

        billPdfer.writeBillPdf ();

        response.setContentLength(memoryOutputStream.size());

        ServletOutputStream out = response.getOutputStream();

        memoryOutputStream.writeTo(out);

        out.flush();
                return null;


You could still use Velocity to create your csv, but you'd do it directly 
with Velocity.mergeTemplate rather than via a servlet.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to