Hello Vikramjit Singh,
Thank you very much for your co-operation.
I am experiencing a strange problem.The File which i want to Download
is
"1003-3.txt",but when i try to download this file the Dialouge box
window ask me for
two options "Open or Save to Disk " .If i go for "Open" ,the File
"Opens" Properly but
when i try to "Save To Disk" the File which is getting Downloaded
is
"downloadFile.htm".
The code is as follows.
try
{
File f= new File("c:/ssmtech/download/customers/1003-3.txt");
res.setContentType("text/plain");
res.setContentLength((int) f.length());
res.setHeader("Content-Disposition","attachment; filename=\"" + f+"\"");
FileInputStream fis = new FileInputStream(f);
ServletOutputStream os = res.getOutputStream();
int i;
while ((i = fis.read()) != -1)
{
os.write(i);
}
fis.close();
os.close();
return res;
}
catch(Exception e)
{
System.out.println("the exception is..."+e);
return res;
}
}
Can you please help me out with this problem.Thanks in advance.
Regards
Sameer
----- Original Message -----
From: "Vikramjit Singh" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 28, 2002 5:09 PM
Subject: Re: File Downloading from server to local disk
> 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
>
>
===========================================================================
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