how can I download directly

I have written a Download method, whenever I click the download button, the download dialog box will be prompt, the dialog box has Open and Save two options, I don't want to give user the Open option, I only want to allow user must choose Save option to save to local machine, how can I do that?

publicvoid DownloadReport(HttpServletRequest request,

HttpServletResponse response, String reportFile)throws Exception{

File fFile =new File(reportFile);

String stFileName = fFile.getName();

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-Disposition","attachment;filename=\""

+ stFileName +"\"");

InputStream isStream =null;

OutputStream out =null;

try{

out = response.getOutputStream();

isStream =new FileInputStream(fFile);

int i;

while ((i = isStream.read()) != -1){

out.write(i);

}

}catch (Exception ioeException){

log.error("Download report error", ioeException);

ioeException.printStackTrace();

thrownew ServletException("Download report error", ioeException);

}finally{

if(isStream!=null) isStream.close();

if(out!=null) out.close();

}

}

[2260 byte] By [henry_22a] at [2007-11-27 8:04:36]
# 1

Sorry, you can't do that. It's the browser's dialog box and so it's the browser's decision.

It might even choose not to display the dialog, as I've often noticed in the case of PDF files; with the right plugin, they open in the browser window without prompting the user.

So you have no control over this. Neither can you control where the file will open; I've seen Excel files open in MS Excel and within the browser window itself.

When you set the content type and all the other headers, you're only telling the browser that the data you're sending now belongs to the file which is of a certain type. How the browser decides to handle this is up to it.

nogoodatcodinga at 2007-7-12 19:47:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...