• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Write Excel file to browser (client)  RSS feed

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that i use to write a excel file and then send it back to user. So the user can save it
or open it in excel. The problem is how do i give a name to this excel file. Because right now, if the
user chooses to open the excel file (rather than saving it). It takes the name of the file same as the name of the servlet
that was used to create the file...ex : http://localhost:7001/app/CreateExcel.do

Here is the snippet of the servlet . I use POI to create excel file


HSSFWorkbook workBook = CreateExcel.writeMSExcel(list.toArray(), lst); // CreateExcel is my helper class
// Write the output
OutputStream out = response.getOutputStream();
workBook.write(out);
out.flush();
out.close();

Please help....
 
Bartender
Posts: 9521
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Servlet forum
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set the header on the servlet response, like below:

response.setHeader("Content-Disposition", "attachment;filename="+fileName);

If you don't want to force the user to download the file, you can use with the inline option:

response.setHeader("Content-Disposition", "inline;filename="+fileName);

Julia
[ November 23, 2004: Message edited by: Julia Reynolds ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!