$("#help").bind("click", function() {
$('#'+searchFormId).form('submit',{
url:urlDownload
});
});
<a class="easyui-linkbutton" style="color: blue" plain="true" iconCls="icon-help" id="help"><strong>快速帮助</strong></a>
@RequestMapping(value = "/download")
public void download(HttpServletRequest request, HttpServletResponse response) {String fileName = "统一对账—快速帮助.docx";
File file = new File("E:/u02/统一对账—快速帮助.docx");
if (file.exists()) {
String userAgent = request.getHeader("User-Agent");
// 针对IE或者以IE为内核的浏览器:
try {
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
} else {
// 非IE浏览器的处理:
fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
}
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
response.setCharacterEncoding("utf-8");
response.setHeader("Cache-Control", "No-cache");
response.setDateHeader("Expires", 0);
response.setContentType("application/force-download");// 设置强制下载不打开
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
byte[] buffer = new byte[1024];
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}