This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes while opening csv file, dialog box opens twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "while opening csv file, dialog box opens twice" Watch "while opening csv file, dialog box opens twice" New topic
Author

while opening csv file, dialog box opens twice

Rakesh Gadre
Ranch Hand

Joined: Feb 22, 2003
Posts: 47
Hi,
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);
FileInputStreamfileStream = null;
try
{
// Open the file to download
fileStream = new FileInputStream (file);
// Read the contents of the disk file into an in memory byte array
intnumberOfBytes = fileStream.available ();
byte contents [] = new byte [numberOfBytes];
fileStream.read (contents);
ServletOutputStream out = res.getOutputStream();
res.setContentType(contentType);

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


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

Thanks in advance,
rakesh
 
 
subject: while opening csv file, dialog box opens twice
 
Similar Threads
Open/Save Dialog Box Should be in the same window.
Open/Save dialog Box appears twice
OPEN/SAVE popoup box comes twice
Problem downloading a file
Open/Save attachments