hi,
I also had the problem in downloading the file. I tried it this way.
First, set the response's content type to APPLICATION/OCTET-STREAM. This
value is not case-sensitive. Then, add an HTTP response header named
Content-Disposition and give it this value:
attachment; filename=theFileName
Where "theFileName" is the default name for the file that appears on the
File Download dialog box. This is normally the same name as the file, but
does not need to be.
Finally, this page demonstrates how to send a file to the user's browser:
// fetch the file
String filename = "companySecret.txt";
String filepath = "C:\\";
response.setContentType(
"APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition",
"attachment; filename=\""
+ filename + "\"");
java.io.FileInputStream fileInputStream =
new java.io.FileInputStream(filepath
+ filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();
I had tried it on tomcat. Hope it helps.
Regards,
Vikramjit Singh,
Systems Engineer,
GTL Ltd.
Ph. 7612929-1031
-----Original Message-----
From: ssmtech [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 28, 2002 3:11 AM
To: [EMAIL PROTECTED]
Subject: File Downloading from server to local disk
Hello All
I have code for downloading a text file a server to the local
system in a JSP page and not as a seperate Servlet,but it is giving me a
"IllegalStateException" ....the snippet of the code is
String fname1 = ""+user.getBusinessId();
String fname2 = ""+user.getAccountId();
String fname = fname1+"-"+fname2+".txt";
response.setContentType("text/plain");
response.setHeader("Content-Disposition","multi-part
attachment;filename=\""+fname+"\";");
ServletOutputStream stream = null;
try {
BufferedInputStream bif = new BufferedInputStream(new
FileInputStream("c:/ssmtech/download/customers/"+fname));
int data;
stream = response.getOutputStream();/// It is giving me a
IllegalStateException out here.....
while(( data = bif.read()) != -1) {
stream.write(data);
}
bif.close();
stream.close();
} catch(Exception e) {
}
finally {
if (stream != null)
stream.close();
}
I am working on a J2EE Application Server.....and on EJB......
Please anybody can help me out with.this .........it is Urgent
Sam
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com