File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes OPEN/SAVE popoup box comes twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "OPEN/SAVE popoup box comes twice" Watch "OPEN/SAVE popoup box comes twice" New topic

OPEN/SAVE popoup box comes twice

Rakesh Gadre
Ranch Hand

Joined: Feb 22, 2003
Posts: 47
I am trying to open a csv file on the browser. I am facing the following problem :

WHen i click on the link that opens the csv file, it popups a window asking whether to OPEN /SAVE the file. If I click on OPEN, instead of opening the file, it again opens the same dialog box. On clicking the OPEN for the second time, it opens the file in excel.

I want the use to see the file only be clicking OPEN button for the first time.

The code snippet is as under:

File file = new File (fileName);
FileInputStream fileStream = null;
// Open the file to download
fileStream = new FileInputStream (file);
// Read the contents of the disk file into an in memory byte array
int numberOfBytes = fileStream.available ();
byte contents [] = new byte [numberOfBytes]; (contents);
ServletOutputStream out = res.getOutputStream();

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

out.write (contents);
out.flush ();


Thanks in advance,
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

It's not a problem with your code. This happened to us using Windows 2000, but not Windows XP with the same code. It probably has to do with browser/operating system settings.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Rakesh Gadre
Ranch Hand

Joined: Feb 22, 2003
Posts: 47

Thanks for the reply. I am using Windows XP. The application uses struts. Wil that make any difference ? If i try the same code seperately using a jsp file directly, it works properly..

I am really stuck up it seems :roll:

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I'll transfer this to the Struts forum and see if anyone has run into this before...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: OPEN/SAVE popoup box comes twice
It's not a secret anymore!