Sponsored Link •
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.
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
> 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
> How many times can this be coded wrong in the browser?
> > And i am using IE5.5 , When download dialog pops up, and choose
> > my question is, is there anything wrong with browser or
> > Pls. reply asp.
> > Thanks
> > > 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.
> > >