当前位置: 代码迷 >> Java Web开发 >> jsp下载有关问题
  详细解决方案

jsp下载有关问题

热度:92   发布时间:2016-04-16 22:05:04.0
jsp下载问题。
本帖最后由 enigma2002 于 2014-07-31 14:55:00 编辑
如果浏览器上有装迅雷之类的插件,会导致下载一个jsp或者html。我总不能每个客户去教他把浏览器上的插件删掉。
请问怎样解决,只用浏览器下载?
下面为下载页面。

<%
//打开指定文件的流信息
String filepath = (String) request.getAttribute("filePath");   //导出文件的路径
filepath = filepath.replace("@", "\\");
String fileName = (String) request.getAttribute("fileName");   //文件名
System.out.println(" filepath + fileName  :  " + filepath+"\\"+fileName);
FileInputStream fs = null;
try {
fs = new FileInputStream(new File(filepath+"\\"+fileName));
}
catch(FileNotFoundException e) 
{
e.printStackTrace();
return;
}
//设置响应头和保存文件名
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename=\""+fileName+"\"");

//写出流信息
int b = 0;
try 
{
OutputStream ops = response.getOutputStream();
while((b=fs.read())!=-1) 
{
ops.write(b);
}
fs.close();
out.clear();
out = pageContext.pushBody();
System.out.println("开始删除");
FileUtil.delAllFile(filepath);  //删除所有文件
System.out.println("删除完成");
}
catch(Exception e) 
{
e.printStackTrace();
}

%> 
------解决方案--------------------
不能,jsp的作用有限
  相关解决方案