Solved

Force File Download and then Close Window after save

Posted on 2002-07-12
7
395 Views
Last Modified: 2012-06-21
I would like users to download jpg's from my site and force the browser not to display the image but to promt the user to save it.  

I am almost there, i just have one problem—I can not get the window that is open through this process to close once the download is complete.  This is what i have so far:

1. Button on window1 opens window2
2. window2 has the following code:
<%
     // fetch the file
     String filename = "SCANDISK.LOG";
     String filepath = "C:\\";
     response.setContentType(
          "APPLICATION/OCTET-STREAM");
     response.setHeader("Content-Disposition",
          "attachment; filename=\""
               + filename + "\"");

     java.io.FileInputStream fileInputStream =
          new java.io.FileInputStream(filepath
               + filename);
     int i;
     while ((i=fileInputStream.read()) != -1) {
          out.write(i);
     }
     fileInputStream.close();
     out.close();

%>
3. user is prompted to save the file
4. after saving the file the window remains open.
5. source code for window2 at this point is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

As you can see by the code, i would be unable to add any onLoad commands to close the window.

I have tried running a function from the window1 that tries to close window2 every 2 seconds, this causes an error beep until the user saves the file.  I assume this happens because it is trying to close a window that is currently locked(not sure if this is the right term).

So can anyone figure a way so that i can send this file to a user and either not have a window open or have it close once the file has been transferred?


Thanks
0
Comment
Question by:menreeq
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 7149258
why do you have to open a second window.. the button should just send the user to your JSP and that will prompt for a download right? No need for a second window or am I missing something?

CJ
0
 

Author Comment

by:menreeq
ID: 7150915
hmmm...maybe i am missing something.  So what changes would make?
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7151246
in your html how about this:

<input type="button" onClick="window.location.href='yourdownloadjsp.jsp';return true;" value="Download File Now!">

CJ
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:menreeq
ID: 7151613
Yes I think there is something missing but it is my fault for not including it.  What you have suggest is fine, however now it leaves window1 (the only window) open after the download is complete...I would like to have this window close after a download (if possible I would like to have it close only after a successful download, I mean only when the user selects saveas and then ok).  Do you know how I can do this?
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7169573
how about closing the window after about 10-15 seconds, after you sure that the user has selected to download the file.

I haven't found any means of getting info from the dialog itself to JavaScript.

CJ
0
 

Author Comment

by:menreeq
ID: 7170212
I tried that, but i was unhappy with the results, sometimes it closed to late and sometimes it tried to early and you would hear an anoying error beep.  I think i will just have to leave the window open...

0
 

Accepted Solution

by:
Jgould earned 0 total points
ID: 7270626
User asked for deletion, anyone objecting?

i would say PAQ and refund

JGould-EE Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what is stuck threads? 3 97
some methods private some are not 8 197
best tutorial on log4j and logging for servlets/jsp codes 1 63
'exit' is not valid keyword in java 14 148
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
With the rapid rise in mobile usage, mobile devices are here to stay and have become an integral part of doing business. Here are 9 great apps for your BYOD environment.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now