You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ilan Azbel <ia...@mdio.net> on 2004/11/25 12:57:17 UTC

vm to return a binary file

Hello,

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.

Thanks
Ilan




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: vm to return a binary file

Posted by Ch...@dlr.de.
Ilan Azbel wrote:
> Hello,
> 
> 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.
> 
> Thanks
> Ilan

Hi,

first, be advised to configure your servlet container to serve binary
data itself or to use your own servlet to create the binary content.

Solutions using Velocity tend to be a bit fragile (character encoding,
whitespace handling, first and only to write to the output stream,
changing response headers, etc.).


I once tried the following, but at some point in velocity history the
response stream was changed - to my memory it was from Writer to
OutputStream.
(please notice the several context tools used to do the task).

#set( $l_file = $ServletContext.getRealPath("/images/$l_fileName") )
#if( $File.fileExists($l_file) )
   #set( $l_fileData = $File.fileRead($l_file) )
   ### check for other image types
   $res.setHeader("Content-type", "image/jpeg")
   $data.Out.write($l_fileData)
#else
   #error( "File $l_file does not exist and cannot be displayed" )
#end


the I rewrote it to:
<br>
<img src="#image($l_fileName)" border="0" />


using a globalMacros.vm:
#macro( image $fileName )/$WEBAPP/images/$fileName#end

This lets the HTTP server do its job.


You could use the first approach in velocity, by placing the outputStream
object into the context and letting the template add the (binary) data.
But be aware! this construct is really fragile - mainly due to the
inconsitent whitespace handling of velocity. Also problesm arise when
using the VelocitylayoutServlet, wher you have to instruct to skip the
layout in such a case...

If you wish an example of creating binary content with a servlet
check the literature, servlets.com, or I can send you a servlet code
that creates button+text images on the fly.

--
:) Christoph Reck

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: vm to return a binary file

Posted by Christoph Reck <ap...@recks.org>.
See the serlvet code in the attachment. Compile into WEB-INF/classes
or into a jar under WEB-INF/lib

some use examples:

globalMacros.vm:#macro( button $parameters )/$WEBAPP/html/buttonFactory.jsp$parameters#end

#set( $tabButton = "$properties.getServletPath('button')" )
#set( $tabButton = "$tabButton?fontSize=12&fontStyle=Italic&tab=true" )
#set( $tabButton = "$tabButton&width=80&insetH=0&insetV=0&border=4" )
#set( $tabButton = "$tabButton&borderColor=0xC0C0C0" )
     <td valign="bottom" height="26" background="$tabButton&text=$tabName">


in the WEB-INF/web.xml add

     <servlet>
         <servlet-name>ButtonFactory</servlet-name>
         <servlet-class>de.dlr.dfd.naomi.ButtonFactory</servlet-class>
     </servlet>

     <servlet-mapping>
         <servlet-name>ButtonFactory</servlet-name>
         <url-pattern>/button/*</url-pattern>
     </servlet-mapping>

I hope this gives an idea.

Cheers,
Christoph

Ilan Azbel wrote:
> Thanks for the help. That code would be much appreciated. Could you also
> tell me to which directory I should compile my .class to?
> 
> Ilan
> 
> 
>>-----Original Message-----
>>From: Christoph Reck [mailto:apache@recks.org]
>>Sent: 25 November 2004 04:17
>>To: Velocity Users List
>>Subject: Re: vm to return a binary file
>>
>>
>>Ilan Azbel wrote:
>>
>>>Hello,
>>>
>>>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.
>>>
>>>Thanks
>>>Ilan
>>
>>Hi,
>>
>>first, be advised to configure your servlet container to serve binary
>>data itself or to use your own servlet to create the binary content.
>>
>>Solutions using Velocity tend to be a bit fragile (character encoding,
>>whitespace handling, first and only to write to the output stream,
>>changing response headers, etc.).
>>
>>
>>I once tried the following, but at some point in velocity history the
>>response stream was changed - to my memory it was from Writer to
>>OutputStream.
>>(please notice the several context tools used to do the task).
>>
>>#set( $l_file = $ServletContext.getRealPath("/images/$l_fileName") )
>>#if( $File.fileExists($l_file) )
>>   #set( $l_fileData = $File.fileRead($l_file) )
>>   ### check for other image types
>>   $res.setHeader("Content-type", "image/jpeg")
>>   $data.Out.write($l_fileData)
>>#else
>>   #error( "File $l_file does not exist and cannot be displayed" )
>>#end
>>
>>
>>the I rewrote it to:
>><br>
>><img src="#image($l_fileName)" border="0" />
>>
>>
>>using a globalMacros.vm:
>>#macro( image $fileName )/$WEBAPP/images/$fileName#end
>>
>>This lets the HTTP server do its job.
>>
>>
>>You could use the first approach in velocity, by placing the outputStream
>>object into the context and letting the template add the (binary) data.
>>But be aware! this construct is really fragile - mainly due to the
>>inconsitent whitespace handling of velocity. Also problesm arise when
>>using the VelocitylayoutServlet, wher you have to instruct to skip the
>>layout in such a case...
>>
>>If you wish an example of creating binary content with a servlet
>>check the literature, servlets.com, or I can send you a servlet code
>>that creates button+text images on the fly.
>>
>>--
>>:) Christoph Reck
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>---
>>Incoming mail is certified Virus Free.
>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>Version: 6.0.801 / Virus Database: 544 - Release Date: 2004/11/24
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 

RE: vm to return a binary file

Posted by Ilan Azbel <ia...@mdio.net>.
Thanks for the help. That code would be much appreciated. Could you also
tell me to which directory I should compile my .class to?

Ilan

> -----Original Message-----
> From: Christoph Reck [mailto:apache@recks.org]
> Sent: 25 November 2004 04:17
> To: Velocity Users List
> Subject: Re: vm to return a binary file
>
>
> Ilan Azbel wrote:
> > Hello,
> >
> > 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.
> >
> > Thanks
> > Ilan
>
> Hi,
>
> first, be advised to configure your servlet container to serve binary
> data itself or to use your own servlet to create the binary content.
>
> Solutions using Velocity tend to be a bit fragile (character encoding,
> whitespace handling, first and only to write to the output stream,
> changing response headers, etc.).
>
>
> I once tried the following, but at some point in velocity history the
> response stream was changed - to my memory it was from Writer to
> OutputStream.
> (please notice the several context tools used to do the task).
>
> #set( $l_file = $ServletContext.getRealPath("/images/$l_fileName") )
> #if( $File.fileExists($l_file) )
>    #set( $l_fileData = $File.fileRead($l_file) )
>    ### check for other image types
>    $res.setHeader("Content-type", "image/jpeg")
>    $data.Out.write($l_fileData)
> #else
>    #error( "File $l_file does not exist and cannot be displayed" )
> #end
>
>
> the I rewrote it to:
> <br>
> <img src="#image($l_fileName)" border="0" />
>
>
> using a globalMacros.vm:
> #macro( image $fileName )/$WEBAPP/images/$fileName#end
>
> This lets the HTTP server do its job.
>
>
> You could use the first approach in velocity, by placing the outputStream
> object into the context and letting the template add the (binary) data.
> But be aware! this construct is really fragile - mainly due to the
> inconsitent whitespace handling of velocity. Also problesm arise when
> using the VelocitylayoutServlet, wher you have to instruct to skip the
> layout in such a case...
>
> If you wish an example of creating binary content with a servlet
> check the literature, servlets.com, or I can send you a servlet code
> that creates button+text images on the fly.
>
> --
> :) Christoph Reck
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.801 / Virus Database: 544 - Release Date: 2004/11/24
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: vm to return a binary file

Posted by Christoph Reck <ap...@recks.org>.
Ilan Azbel wrote:
> Hello,
> 
> 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.
> 
> Thanks
> Ilan

Hi,

first, be advised to configure your servlet container to serve binary
data itself or to use your own servlet to create the binary content.

Solutions using Velocity tend to be a bit fragile (character encoding,
whitespace handling, first and only to write to the output stream,
changing response headers, etc.).


I once tried the following, but at some point in velocity history the
response stream was changed - to my memory it was from Writer to
OutputStream.
(please notice the several context tools used to do the task).

#set( $l_file = $ServletContext.getRealPath("/images/$l_fileName") )
#if( $File.fileExists($l_file) )
   #set( $l_fileData = $File.fileRead($l_file) )
   ### check for other image types
   $res.setHeader("Content-type", "image/jpeg")
   $data.Out.write($l_fileData)
#else
   #error( "File $l_file does not exist and cannot be displayed" )
#end


the I rewrote it to:
<br>
<img src="#image($l_fileName)" border="0" />


using a globalMacros.vm:
#macro( image $fileName )/$WEBAPP/images/$fileName#end

This lets the HTTP server do its job.


You could use the first approach in velocity, by placing the outputStream
object into the context and letting the template add the (binary) data.
But be aware! this construct is really fragile - mainly due to the
inconsitent whitespace handling of velocity. Also problesm arise when
using the VelocitylayoutServlet, wher you have to instruct to skip the
layout in such a case...

If you wish an example of creating binary content with a servlet
check the literature, servlets.com, or I can send you a servlet code
that creates button+text images on the fly.

--
:) Christoph Reck


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Attention administrator: Please remove me. Thank you

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi John,

> yes, please remove john@sfhypnosis.com and john@rothfield.com

Please send your request to velocity-user-owner@jakarta.apache.org, and
wait for a while.  (Note, that it might be a _long_ while.)

> > ---- WELCOME to velocity-user@jakarta.apache.org ----
> > If despite following these instructions, you do not get the
> > desired results, please contact my owner at
> > velocity-user-owner@jakarta.apache.org. Please be patient, my owner is a
> > lot slower than I am ;-)
> > ---- WELCOME to velocity-user@jakarta.apache.org ----

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Attention administrator: Please remove me. Thank you

Posted by John Rothfield <jo...@rothfield.com>.
yes, please remove john@sfhypnosis.com and john@rothfield.com

Thanks, John
707-538-5133


Shinobu Kawai wrote:
> Hi John,
> 
> On Thu, 25 Nov 2004 11:55:31 -0800, John Rothfield <jo...@rothfield.com> wrote:
> 
>>I've tried a few times to unsubscribe but with no success.
>>Please unsubscribe me.
>>
>><ve...@jakarta.apache.org>
>>
>>My email configuration has changed.
> 
> 
> Are you trying to remove "john@rothfield.com" from the list?
> 
> 
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> 
> 
> If you are, and you have sent to the above address from
> "john@rothfield.com", and still have no success, you really need help
> from the admin.  Quoting the welcome mail,
> 
> ---- WELCOME to velocity-user@jakarta.apache.org ----
> If despite following these instructions, you do not get the
> desired results, please contact my owner at
> velocity-user-owner@jakarta.apache.org. Please be patient, my owner is a
> lot slower than I am ;-)
> ---- WELCOME to velocity-user@jakarta.apache.org ----
> 
> ## Were you successful in removing your old "john@sfhypnosis.com" from the list?
> 
> Best regards,
> -- Shinobu Kawai
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Attention administrator: Please remove me. Thank you

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi John,

On Thu, 25 Nov 2004 11:55:31 -0800, John Rothfield <jo...@rothfield.com> wrote:
> I've tried a few times to unsubscribe but with no success.
> Please unsubscribe me.
> 
> <ve...@jakarta.apache.org>
> 
> My email configuration has changed.

Are you trying to remove "john@rothfield.com" from the list?

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org

If you are, and you have sent to the above address from
"john@rothfield.com", and still have no success, you really need help
from the admin.  Quoting the welcome mail,

---- WELCOME to velocity-user@jakarta.apache.org ----
If despite following these instructions, you do not get the
desired results, please contact my owner at
velocity-user-owner@jakarta.apache.org. Please be patient, my owner is a
lot slower than I am ;-)
---- WELCOME to velocity-user@jakarta.apache.org ----

## Were you successful in removing your old "john@sfhypnosis.com" from the list?

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Attention administrator: Please remove me. Thank you

Posted by John Rothfield <jo...@rothfield.com>.
I've tried a few times to unsubscribe but with no success.
Please unsubscribe me.

<ve...@jakarta.apache.org>

My email configuration has changed.

Thanks, John
707-538-5133

Mike Kienenberger wrote:
> Ilan Azbel <ia...@mdio.net> 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: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: vm to return a binary file

Posted by Mike Kienenberger <mk...@alaska.net>.
Ilan Azbel <ia...@mdio.net> wrote:
> I am using the Turbine framework. The thing is, I want to leverage off the
> existing database connections that turbine has already made, so I don't 
want
> to create something completely independant. How do I go about doing this?

I don't know enough about turbine to say, but if there's separation between 
the presentation layer and control layer, there must be a way to manually 
construct a response.

In struts, that's done by returning null from an action (indicating that 
you've already built a response object and to not generate a forward).

You might have better chances of getting an answer on the turbine mailing 
list as this is really a turbine question and not a velocity one.

In any case, the code below should be of some help.   It shows what values 
you need to set on a response object and how to write your output into it.  
That should be pretty much the same for any servlet framework.

-Mike



> > -----Original Message-----
> > From: Mike Kienenberger [mailto:mkienenb@alaska.net]
> > Sent: 25 November 2004 03:43
> > To: iazbel@mdio.net
> > Cc: velocity-user@jakarta.apache.org
> > Subject: Re: vm to return a binary file
> >
> >
> > Ilan Azbel <ia...@mdio.net> 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: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---
> > Incoming mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.801 / Virus Database: 544 - Release Date: 2004/11/24
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: vm to return a binary file

Posted by Ilan Azbel <ia...@mdio.net>.
I am using the Turbine framework. The thing is, I want to leverage off the
existing database connections that turbine has already made, so I don't want
to create something completely independant. How do I go about doing this?


> -----Original Message-----
> From: Mike Kienenberger [mailto:mkienenb@alaska.net]
> Sent: 25 November 2004 03:43
> To: iazbel@mdio.net
> Cc: velocity-user@jakarta.apache.org
> Subject: Re: vm to return a binary file
>
>
> Ilan Azbel <ia...@mdio.net> 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: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.801 / Virus Database: 544 - Release Date: 2004/11/24
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: vm to return a binary file

Posted by Mike Kienenberger <mk...@alaska.net>.
Ilan Azbel <ia...@mdio.net> 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: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org