81,122
社区成员




public String download() throws Exception {
try {
String filePath = servletRequest.getParameter("filePath");
File file = new File(filePath);
String fileName = file.getName();
fileName = URLEncoder.encode(fileName, "utf-8");
fileName = fileName.replace('+', ' ');
servletResponse.setContentType("application/x-download");
servletResponse.addHeader("Content-Disposition",
"attachment;filename=" + fileName);
excelStream = new FileInputStream(file);
}
catch(Exception e) {
write(Tool.getErrorMsg(e.getMessage()));
return ERROR;
}
return SUCCESS;
}
<input id="download" type="button" value="下载word" />
$("#download").click(function(){
//请求后台的下载代码
window.location.href="servletName";
});