upload file to client computer

In my application i have to generate reports .Earlier we show reports only injsp pages .now i try that user can also download file to his /her computer.i generate reports in excel format now i have to upload it to client machine .how to do this Thanks
[300 byte] By [d17maya] at [2007-10-3 1:03:38]
# 1

Is this still a web application? You really mean they will download the excel files right?

A very simple way is to output a content type of Content-Type: application/vnd.ms-excel and an HTML table and then if your clients are using IE and Excel it will load that as an excel sheet. You can even have formulas in this. It's really quite simple.

cotton.ma at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 2
I really want that they can download file .Thanks d17may
d17maya at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 3
Use a servlet's output stream to send the file. Make sure that you set the appropriate MIME type in the response first.
CeciNEstPasUnProgrammeura at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 4
Can u plz give sample code for excel filesThanks d17may
d17maya at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 5
> Can u plz give sample code for excel files> Thanks d17mayThere are thousands of samples out there explaining how to write a file. Anyway, you should be able to come up with it yourself, it's not rocket science.
CeciNEstPasUnProgrammeura at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 6

I write this code file is copied to client computer but it gives error in opening

My code is

ServletOutputStream out = null;

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

response.setHeader("Content-Disposition", "attachment; filename=sample.xls");

FileInputStream f=new FileInputStream("c:\\sample.xls");

FileChannel fc=f.getChannel();

try

{

byte[] data = new byte[(int)fc.size()];

out = response.getOutputStream();

out.write(data);

}

catch(IOException e){}

finally

{

if(out != null)

{

try

{

out.flush();

out.close();

}

catch(IOException e){}

}

}

Thanks d17may

d17maya at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 7
> I write this code file is copied to client computer> but it gives error in opening> My code is unreadable. http://forum.java.sun.com/help.jspa?sec=formatting
CeciNEstPasUnProgrammeura at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...
# 8
> catch(IOException e){}You deserve all the problems you get.Which error do you get, by the way? I tried mind-reading, but your brainwaves are too fuzzy.
CeciNEstPasUnProgrammeura at 2007-7-14 17:59:53 > top of Java-index,Java Essentials,Java Programming...