public ActionForward dnowload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
OutputStream out;
InputStream in;
// 获取filename请求参数
String filename = request.getParameter("fileNames");
if (filename == null)
{
out = response.getOutputStream();
out.write("Please input filename.".getBytes());
out.close();
return null;
}
// 获得读取本地文件的输入流
in=new FileInputStream("f:\\upload\\"+filename);
int length= in.available();
// 设置喷响应正文的MIMI类型
response.setContentType("application/force-download");
response.setHeader("Content-Length", String.valueOf(length));
response.setHeader("Content-Disposition", "attachment;filename=\"" +filename + "\" ");
// 把本地文件中的数据发送给客户
out=response.getOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[512];
while ((bytesRead = in.read(buffer))!=-1)
{
out.write(buffer, 0, bytesRead);
}
in.close();
out.close();
return null;
}
jsp下载
最新推荐文章于 2022-07-25 10:50:44 发布