点击按钮下载的时候会有一个弹出框,可以选择是打开还是下载,请大神们给出一个代码实例
http://blog.csdn.net/arui_email/article/details/9041283
//强制要求为下载,防止有些浏览器调用默认打开程序打开而不下载
response.setContentType("application/force-download");
//获取文件
File fileLoad = new File(path);
//下载时文件显示的名字
String fileDisplayName = null;
try {
if(displayFileName != null && (!"".equals(displayFileName))){
fileDisplayName = URLEncoder.encode(displayFileName, "UTF-8");
}else{
fileDisplayName = fileLoad.getName();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//设置下载时的文件名
response.setHeader("Content-disposition", "attachment;filename="+fileDisplayName);
//当下载文件名为中文等Unicode字符时,可能导致乱码,此时需要将文件名重新编码为UTF-8
//采用ISO8859-1编码
//response.setHeader("Content-disposition","attachment; filename="+new String(fileLoad.getName().getBytes("iso-8859-1"),"UTF-8"));
//采用UTF-8编码
//response.setHeader("Content-disposition","attachment; filename="+URLEncoder.encode(fileLoad.getName(), "UTF-8"));
try {
OutputStream ops = null;
FileInputStream fis = null;
long fileLength = fileLoad.length();
String length = String.valueOf(fileLength);
response.setHeader("Content_Length", length);
ops = response.getOutputStream();
fis = new FileInputStream(fileLoad);
byte b[] = new byte[2048];
int i = 0;
while((i = fis.read(b))!= -1){
ops.write(b, 0, i);
}
ops.flush();
if(fis != null){
fis.close();
fis = null;
}
} catch (Exception e) {
e.printStackTrace();
}
想问一下,download.jsp应该放在什么路径下