download window

Hi all,I want to show a download window to download the files as we will get in yahoo. I want to show this in jsp file. Can anyone please help me regarding this.Thank you all
[195 byte] By [sridevi123a] at [2007-10-3 1:24:42]
# 1

If "download window" is that little dialog the browser shows about whether to download a file: it's a browser feature. There is no such thing in HTML. For it to pop up, you need to stream out the data accompanied with the according MIME type. Definitely not the thing JSPs can do. You need a servlet for that.

CeciNEstPasUnProgrammeura at 2007-7-14 18:22:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi, this can be done.

Write a new jsp, in which you read the file using a stream and write this stream to the response stream mentioning the application type.

You would call this jsp from a link or a button to open in a new window (like yahoo download). And this jsp would prompt with a dialog box to save the file. (A disadvantage is that, the new window cannot be closed on its own after download is complete)

Here is an excerpt of code from one of my jsps :

<%

response.setContentType("application/octet-stream");

response.setHeader("Content-Disposition", "attachment; filename=\"FairValueFiles" + (new SimpleDateFormat("MM-dd-yyyy").format(new Date())) + ".zip\"");

%>

<%

byte[] buffer = new byte[1024];

String outFilename = "/dir/myFile.zip";

FileInputStream fin = new FileInputStream(outFilename);

BufferedInputStream bin = new BufferedInputStream(fin);

int length;

while ((length = bin.read(buffer)) != -1)

{

response.getOutputStream().write(buffer, 0, length);

}

fin.close();

bin.close();

response.getOutputStream().close();

%>

ragh_dra at 2007-7-14 18:22:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...