forcing download without prompting for file dialog box

Can anyone let me know how to download a file in an web based application without prompting for a file download dialog box using java(servlet or JSP) or How do i raise a file download dialog box for downloading a file to the clients machine using java(servlet or JSP).

thanks

chandru

[309 byte] By [chandruos] at [2007-9-26 2:46:40]
# 1

Here is the code for raising open/save dialog

if you don't want that

comment this line

//res.setHeader("Content-Disposition","attachment;filename="+fname+".pdf;");

public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException

{

String fname=req.getParameter("fname");

String folder1=req.getParameter("folder");

String folder=folder1+"/"+fname+".pdf";

res.setContentType("application/pdf");

res.setHeader("Content-Disposition","attachment;filename="+fname+".pdf;");

ServletOutputStream stream = res.getOutputStream();

BufferedInputStream fif =

new BufferedInputStream(new FileInputStream(folder));

int data;

while((data = fif.read()) != -1) {

stream.write(data);

}PrintWriter out = res.getWriter();

fif.close();

stream.close();

}

priviet at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks a lot,Is it possible to download without prompting for file download dialog? I mean, directly downloading the filie once the user clicks on the link. Let me know the answer to it.chandru
chandruos at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
ya but it will just open that file in browser then user has to save it
priviet at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Suposing I write a virus and hide it behind a normal html link, perhaps in an email. You click on the link and the virus is downloaded to your harddrive without you being informed of it in any way. It would be in a pretty good position to be accidentally executed at some point after that.

That is why you have to have the file download warning on links to files. The alternative is a total security liability.

Breakfast at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

you cannot force to download without the file open dialog..

if the appropriate mimetype is registered in your workstation without asking like word,text,html,excel etc.. if that programs already there in your local machines..

for IE,windows register that appcation by going to filetype from view|explorer|options and register the content type and mime type.. for the application you want to open..

za

zakir_sh at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
I tried your script, and rather than downloading the required file, it downloaded the scripted file itself! Any Ideas?Ozz
ozzwald at 2007-6-29 10:30:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...