The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000



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.


New window OR download dialog

Posted by Gary Macey on June 01, 2001 at 7:03 AM

I have a browser window that contains hyperlinks to web classes that retrieve a file content and filename from the database. I have created a finite list of file types that will automatically open up the file with the associated application (e.g. DOC - Word, PDF - Acrobat etc.), otherwise it opens up the download dialog box and offers the user the option to either open or save the file.

I have managed to pass in the existing filename as the default if the user chooses to save, ensuring that it is a String type worked for this.

If the user chooses to open the uncatered file type then they are offered the "Open with" dialog box.

My problem is that for the catered file types I want to spawn a new browser window, as the download dialog forces, but don't seem to be able to do it from within my web class. Is there some HTTP header information that I can set to force the opening of a new browser window? How does the download dialog box force the opening of a new browser window?

If anyone could suggest a solution for this then it would be much appreciated.


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

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

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

> > >

Salil V Gangal


Sponsored Links

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