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]

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();
}
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
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.
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