How to download a file from a server ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, January 11, 2007 10:49 AM

Hi - I have to create a .csv from the data in the database and the user should have the option to download the file on the fly when it is created. I dont want to save the file in the server. I'm trying to find a way to do this. If anyone have any idea please help.


Thanks in advance, Chimbu.

Re: How to download a file from a server ?

Posted By:   Anonymous  
Posted On:   Saturday, January 13, 2007 02:17 AM

read the contents from database and store it....

call the following method from your servlet doPost/doGet method



//file contents are set in previous jsp and this servlet is called
HttpSession session = req.getSession();
// read the contents from byte arrary previously stored
byte []fileContents = (byte[])session.getAttribute("fileContents");
if( fileContents != null ){

res.setContentType("application/x-download");
res.setHeader("Content-Disposition", "attachment; filename="
+ "SDiffLic");

// Send the file.
OutputStream out = res.getOutputStream();
out.write(fileContents);
}

About | Sitemap | Contact