aspose file tools*
The moose likes Servlets and the fly likes Write Excel file to browser (client) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Write Excel file to browser (client)" Watch "Write Excel file to browser (client)" New topic
Author

Write Excel file to browser (client)

Pappu Kumar
Ranch Hand

Joined: Oct 01, 2002
Posts: 69
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....
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8715
    
    6

Moving this to the Servlet forum


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Julia Reynolds
Ranch Hand

Joined: May 31, 2001
Posts: 123
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Write Excel file to browser (client)
 
Similar Threads
How applet read a excel file thought weblogic app server
To the man who shares my namesake...Aaron Mulder
alias name for jsp file
HelloWorldServlet in Weblogic 6.0
wild character is not working in the servlet mapping in WLS7.0