Excel file download fron server

Hi,I have developed to download excel from server using jsp,struts.It will download from server but in text format instead of excel and also in different file name.How to change format and change name of the file?Plz help me.......
[266 byte] By [mm_302002a] at [2007-10-2 16:20:46]
# 1

If you mean a text format like CSV, you'll have to use the Apache POI package to turn that CSV into an excel sheet. You may need to implement that conversion yourself.

http://jakarta.apache.org/poi/index.html

As for the download, you'll need to do the conversion and then get the byte output, which you output to the browser. Using HTTP headers you can control if the file is opened inside the browser or downloaded, and which filename that the file will get. To force a download box, use the following headers:

response.setContentType("application/octet-stream");

response.setHeader("Content-Disposition","attachment; filename=\"FILENAME\"");

response.setContentLength(LENGTH_IN_BYTES);

<output excel content to browser here>

In the above code you need to replace FILENAME and LENGTH_IN_BYTES with the filename you want the excel file to have, and the size of that excel file in bytes.

If you want more information, search this forum. JSP/servlet file download questions get asked almost every day.

gimbal2a at 2007-7-13 17:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...