velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bailey, David" <David.Bai...@pearson.com>
Subject RE: Velocity View Servlet - how to serve page w/o HTTP header
Date Fri, 05 Dec 2008 15:40:00 GMT
For anyone who might run into this issue in the future, this is what did
the trick (just a minor change from Claude's original suggestion):

	#set($junk=$response.setContentType('text/csv'))
	#set($junk=$response.setHeader('Content-disposition: attachment;
filename=reportOutput.csv'))

This also has the advantage of allowing me to give the file a .csv
extension and my browser still gives me the 'save or open' behavior,
which is something it doesn't even do for static CSV files!

Thanks again Nathan and Claude, and apologies for the initial red
herring.

--dave

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: Thursday, December 04, 2008 5:19 PM
To: Velocity Users List
Subject: Re: Velocity View Servlet - how to serve page w/o HTTP header

yeah, the Content-type and Content-disposition headers that are set for
the response.  You can set those first thing in the template as Claude
showed, or you can extend the VVS and override the setContentType method
to set those both there.  there is also a config option for content
type, but not for content disposition.

On Thu, Dec 4, 2008 at 3:11 PM, Bailey, David <David.Bailey@pearson.com>
wrote:
> Yeah, my apologies.  HTTP headers and so forth have nothing to do with

> my problem.
>
> For some reason, when I load static content (filename.xls) from my web

> server, my browser recognizes it as a special file and prompts me to 
> save/open with associated application.
>
> When I register *.xls as a file I want the Velocity View Servlet to 
> process, for some reason the browser simply displays the file content,

> rather than prompting me.
>
> I had surmised that this was happening because VVS was throwing HTML 
> tags around things, but I see now that my browser was doing it (I 
> would save the displayed content to my desktop, and the browser very 
> nicely saved the .xls file with HTML formatting).
>
> So my earlier statement about HTTP headers was totally off the mark.
> Does anyone have any clue why my browser is treating content 
> dynamically generated by VVS differently from static content on the 
> web server's filesystem?
>
> Thanks,
> --dave
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: Thursday, December 04, 2008 4:45 PM
> To: Velocity Users List
> Subject: Re: Velocity View Servlet - how to serve page w/o HTTP header
>
> I agree with Claude, HTTP headers are necessary since you are using 
> the HTTP protocol.  You just need to set the proper Content-type and 
> Content-disposition.  And i also wonder what you mean by HTTP headers,

> since you refer to HTTP footers as well.  I don't think there's any 
> such thing as HTTP footers.  Do you mean HTML headers and footers?
> Are you using the VelocityLayoutServlet perchance?
>
> On Thu, Dec 4, 2008 at 2:05 PM, Bailey, David 
> <David.Bailey@pearson.com>
> 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
>
>
> ---------------------------------------------------------------------
> 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


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


Mime
View raw message