views:

96

answers:

1

I have a JSP file which creates an Excel document.

I want to dynamically set the name of the file to be downloaded.

This is how I set the file name to "test.xsl":

<% response.setContentType("application/vnd.ms-excel"); 
   response.setHeader("Content-Disposition","attachment; filename=" + "test.xsl" ); 
%>

How can I set the file name to be test-${today's date}.xsl ( i.e. test-20100805.xsl ) ?

+2  A: 
String fname = MessageFormat.format( 
    "test-{0, date, yyyyMMdd}.xsl", new Object [] { new Date() } );
response.setHeader("Content-Disposition","attachment; filename=" + fname );

I think this should work for you.

Shawn D.
Something is not quite right here.
jeph perro
Ah, just needed to remove the spaces inside the {braces}:test-{0,date,yyyyMMdd}.xsl
jeph perro
Oops. Sorry, my fault for trying to make it more readable. :-)
Shawn D.