Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 9492
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 ]
 
Get out of my mind! Look! A tiny ad!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!