Regarding saving and opening excel files using servlets

Hi,

I have some data on a jsp.I made an excel file with that data using apache''s POI.Then i have to save the file using a servlet.

I am copying the code below :

All the data which i needed from JSP is wriiten to a ByteArrayOutputStream "baosPDF" using apachs's POI

StringBuffer sbFilename = new StringBuffer();

sbFilename.append("DealerCsa_Report_");

sbFilename.append(System.currentTimeMillis());

sbFilename.append(".xls");

StringBuffer sbContentDispValue = new StringBuffer();

sbContentDispValue.append("attachment");

sbContentDispValue.append("; filename=");

sbContentDispValue.append(sbFilename);

response.setHeader("Content-disposition",sbContentDispValue.toString());

response.setContentType("application/vnd.ms-excel");

sos = response.getOutputStream();

baosPDF.writeTo(sos); // baosPDF is ByteArrayOutputStream whcih

//contains excel sheet

sos.flush();

baosPDF.flush();

baosPDF.close();

So for the above code when i am trying to save the file it is saving but when i am trying to open it i am getting error as

"C:\Documents and Settings\rakeshbh\Local Settings\Temporary Internet Files\Content.IE5\WHAN8HYR\DealerCsa_Report_117945678[1].xls could not be found.Check the spelling of the file name, and verify that the file location is correct."

Can any one please tell me why i was not able to open the file and what should be done to open the file .

[1503 byte] By [rakesh_bhadraa] at [2007-11-27 4:40:07]
# 1
Hi,Check whether the file exists in the correct location. If exists, select the file and right click and check the extension.For example myexcel.xls.xlsIf extension appears twice remove one xls.I experienced the same problem before.
AnanSmritia at 2007-7-12 9:51:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi,Thanks for ur reply..I have checked in the temporay internet files ,the file itself is not there.I don't understand why the file is not getting saved there.Do u have any idea regarding the above thing.Thanks in advance
rakesh_bhadraa at 2007-7-12 9:51:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Check your code whether it works properly.
AnanSmritia at 2007-7-12 9:51:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> Check your code whether it works properly.

Hi,

Yes when i am trying to save the file it is saving.

But when i try to open it it is giving me error.

i am setting the content type to ("application/vnd.ms-excel")

and Content-disposition to attachment ; filename=abc.xls .

And as mentioned in the first post i am getting the data in

byteouputstream and wrting that byte output stream to

servletout put stream and flushing it ..

Is there anything else i need to do..

It would be really grateful if any one helps me regarding this .

rakesh_bhadraa at 2007-7-12 9:51:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Since you're able to save the file, the problem doens't seem to be in your code; probably with your browser. Try a different browser, user Firefox or something.

Also, it could be a problem with memory on your system. How big is the file anyway? Try with a small file first.

And lastly, it may just be a problem with the filename being too long. Try with a simple filename first; maybe just 1 or 2 characters.

nogoodatcodinga at 2007-7-12 9:51:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...