try {
String file= request.getRealPath("项目中文件路径");
InputStream is = new FileInputStream(file);
response.reset(); // 必要地清除response中的缓存信息
response.setHeader("Content-Disposition", "p_w_upload; filename=" + file);
response.setContentType("application/vnd.ms-excel");//根据个人需要,这个是下载文件的类型
javax.servlet.ServletOutputStream out = response.getOutputStream();
byte[] content = new byte[1024];
int length = 0;
while ((length = is.read(content)) != -1) {
out.write(content, 0, length);
}
out.write(content);
out.flush();
out.close();
} catch (Exception e) {
handleAjaxException(e, "下载", true);
}