Hello Sameer,
Are you using frame set with in which you have this html file which will
call a servlet and that servlet will actually download the .txt file that
you are giving it as download, isn't it?

And your download file name is "downloadFile.htm" right?

If you use frame set and inside that frame set you download any thing then
your download file will have the name of your parent frame name and it will
contain the html code of your parent frame.

I had the same problem previously. I have solved this problem using some
other work around.

I presume all that I have explained above were true and I will try to give
the idea that I have implemented to solve this problem.

Actually the problem is because the download file has the file name of the
name which is there in the address bar.
So, If the attachment file name is from the same file that is there in the
address bar it downloads the attachment file other wise it trys to download
the file in the address bar.

So I exploited this behaviour of browser and I tried like I called the file
downloading JSP/servlet in a serperate new window, I set the new Window's
width and height as 10,10 respectivley. So that the window won't be visible
for the user.

Then I wrote one java script method to close that window after a few
seconds. So the window will come and sit in your start menu bar, after some
time it will automatically closed by that Javascript function.


I hope this solves your problem..
Regards
Yogaraj

-----Original Message-----
From: ssmtech [mailto:[EMAIL PROTECTED]]
Sent: Sunday, March 31, 2002 10:44 PM
To: [EMAIL PROTECTED]
Subject: Re: File Downloading from server to local disk


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

===========================================================================
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


"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this
communication is strictly Prohibited.
If you have received this message by error, please notify us
immediately, return the original mail to the sender and delete the
message from your system."

===========================================================================
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

Reply via email to