Setting file name for a downloaded file

I've set up a file download using code I've gleaned from jsf forums. However, the file name is not being set correctly. When the user downloads File.doc, it shows up as downloadPage.jsf. Am I setting the header correctly?

publicclass VendorInfoBeanextends AbstractViewController{

public VendorInfoBean(){

}

public String downloadVendorApp(){

ExternalContext context = getExternalContext();

String path = context.getInitParameter("externalFiles");

String filename ="Vendor_Application_e_Form.doc";

String fullFileName = path + filename;

File file =new File(fullFileName);

HttpServletResponse response = (HttpServletResponse) context.getResponse();

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

response.setContentLength((int) file.length());

response.setContentType("application/msword");

try{

FileInputStream in =new FileInputStream(file);

OutputStream out = response.getOutputStream();

// Copy the contents of the file to the output stream

byte[] buf =newbyte[1024];

int count;

while ((count = in.read(buf)) >= 0){

out.write(buf, 0, count);

}

in.close();

//out.write(bytes);

out.flush();

out.close();

FacesContext.getCurrentInstance().responseComplete();

}catch (IOException ex){

ex.printStackTrace();

}

returnnull;

}

}

[2571 byte] By [James_Ra] at [2007-10-2 17:30:36]
# 1
i don't put quotes around the filename, plus i seem to have better luck with inline instead of attachment. i.e.:response.setHeader("Content-Disposition", "inline; filename=" + filename);
scott_longa at 2007-7-13 18:47:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I'll try that.Thanks!
James_Ra at 2007-7-13 18:47:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

StringBuffer sbFilename = new StringBuffer();

sbFilename.append("adeem");

sbFilename.append(".doc");

StringBuffer sbContentDispValue = new StringBuffer();

sbContentDispValue.append("attachment");

sbContentDispValue.append("; filename=");

sbContentDispValue.append(sbFilename);

HttpServletResponse response = (HttpServletResponse) context.getResponse();

response.setHeader("Content-Disposition", sbContentDispValue.toString());

i think this will work .. if not let me know i will give some code that will work for u then ...

adeema at 2007-7-13 18:47:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...