velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claude Brisson <cla...@renegat.net>
Subject Re: Velocity View Servlet - how to serve page w/o HTTP header
Date Thu, 04 Dec 2008 22:23:44 GMT
The problem does not come from the fact that there are HTTP headers.
Whatever type of files you are serving, you are doing so by means of the
HTTP protocol, which requires HTTP headers, as long as users are
accessing your application via a browser.

You can put:

#set($response.contentType('text/csv')##

(or whatever mime type that fulfills your needs) at the beginning of
your csv template.

You can even add another HTTP header which explicitly tells the browser
that the content is a file attachment:

#set($junk=$response.setHeader('Content-disposition: attachment; filename=myexport.csv'))##

I don't really know if both -or only one of them- are necessary, make
some tests...


  Claude

On jeu, 2008-12-04 at 16:05 -0600, Bailey, David wrote:
> I have developed a servlet which is really nothing more than the
> Velocity View Servlet using a toolbox of tools I wrote and plugged in
> using the toolbox.xml file.  This has served me quite well, until now.
> 
> My servlet is basically an order entry system, and one component of the
> system is a report generator.  In my initial implementation, the reports
> are generated in HTML.  However, I have received a new feature request
> that the reports be generated for the user in CSV format as well.
> 
> I have attempted to satisfy this enhancement request by setting the
> <servlet-mapping> element in web.xml to send both *.vm and *.xls files
> through Velocity, and then wrote a new VTL template with a .xls
> extension.  But it seems that the Velocity View Servlet always wants to
> include HTTP headers in the files it parses and serves, and this is
> cumbersome from an end-user perspective  (the existence of HTTP headers
> makes it cumbersome for the user to save the content as a true CSV
> file).
> 
> I've browsed the archives and discovered that I can set the content-type
> of a served file using velocity.properties, but I don't see any way to
> suppress the HTTP header altogether.  Is my only choice here to subclass
> VelocityViewServlet so I can strip out the HTTP headers (and footer)
> before the page is served, or is there some other solution, possibly via
> velocity.properties?
> 
> Thanks,
> --dave
> 
> P.S.  Sorry if this gets posted twice --- it didn't seem to post the
> first time.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 


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


Mime
View raw message