The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

this works for me

Posted by mark on August 22, 2001 at 9:42 PM

It appears that an answer isn't fully made, so I will add a similar one.
you can figure out the ... I'm sure.
works well for me. thanks for the clue!

response.setContentType("application/x-zip-compressed");
ServletOutputStream out = response.getOutputStream();
String fileName = "some.zip";
...
response.setHeader("Content-Disposition","attachment; filename=" + fileName);
while (fin.available() > 0) {
int available = fin.available();
if (available > 51200) available = 51200;
byte [] bytes = new byte[available];
fin.read(bytes);
out.write(bytes);
}
out.close();


> > Hi,
> > I have no problem for using the following java code in my *serlvet; however, I do have problem for my previous window keeps running after the download completed and pop-up window clsoed. Any ideals ?

> > my JAVA code:
> > // set response header
> > res.setHeader("Content-Disposition",
> > "attachment; filename=" + lstrSvcName + lstrSvcNo + "V" + lstrSvcVersion + user.getLogin()+ lstrDate + "." + lstrSvcType.toLowerCase() + ";");

> > Thnaks,
> > Regares,
> > - River

> > > I also got strange errors trying to download a file from a java servlet using a JSP page.

> > > There seems to be a bug(s) in IE 5.5 service pack 1; with setting content-disposition attachment; filename=file.qif

> > > Check out:
> > > http://support.microsoft.com/support/kb/articles/Q281/1/19.ASP
> > > http://support.microsoft.com/support/kb/articles/Q267/9/91.Asp

> > > This page identifies the problem in IE 5.5 sp1, and says there is a fix in service pack one. I downloaded the latest IE 5.5 sp1 version, and still have the same problem.

> > > I do get the file save as pop-up, but the default file name is not what im setting it to; it is picking up the name of the servlet / page, and the data saved is not what the servlet sent; ts the contents of the web page (the actual html code).

> > > ho hum. If anyone has more insight / info on how to
> > > code a servlet to download dynamically created data (unique) to each person, so that it will work in almost any browser, please let me know.

> > > Netscaps seems to work fine, but IE works in some versions, and not in othere. IE had a problem almost like this in IE 4.01
> > > only you never got the save-as pop-up

> > > see:
> > > support.microsoft.com/support/kb/articles/q182/3/15.asp

> > > How many times can this be coded wrong in the browser?

> > > Thanks!

> > >
> > > > Hello there,
> > > > i am facing some wired problem similar tio this.
> > > > I;ve used res.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\";")

> > > > And i am using IE5.5 , When download dialog pops up, and choose
> > > > to save as, i do not get filename which was specified. Rather get
> > > > current webpage file name, but choosing to open twice and third
> > > > click to save as it gets right filename

> > > > my question is, is there anything wrong with browser or
> > > > i am not writting routine properly if so can you pls. just
> > > > list the steps? Do i have to close the stream when write is
> > > > complete?

> > > > Pls. reply asp.

> > > > Thanks
> > > > -Raj

> > >
> > > > > Hi krnbhaskar,

> > > > > I just changed the line from
> > > > >

res.setHeader("Content-Disposition","attachment; filename=\"" + downloadFile + "\";");

> > > > > to
> > > > >

res.setHeader("Content-Disposition","attachment; filename=\"" + "abc.txt" + "\";");

> > > > >

Then I ran the servlet using Netscape and IE both and both gave me the correct file name (abc) and correct file type (plain text - Netscape, text document - IE) to save. So my guess is that your program is correct.

> > > > >

I don't know why it showed you different names, but I'm speculating that perhaps it is because of differnt file extensions getting recognized differently by the browsers. Perhaps you may want to try to hardcode the name the way I did to test out whether Netscape and IE are still behaving differently when extension is .txt or whether they behave differently when some other extension comes into picture.

> > > > >

Regards,
Salil V Gangal






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us