Download document
程序员文章站
2022-03-18 19:48:21
...
<a href="${contextPath}/announcementinteajx/downloadAnnoAttachDocument.action?id='+docuAr[i].id+'">'+docuAr[i].displayName+'</a>
@RequestMapping(value="/downloadAnnoAttachDocument", method = RequestMethod.GET)
public @ResponseBody ModelAndView downloadAnnoAttachDocument(HttpServletRequest request,
HttpServletResponse response) throws Exception{
long annoAttachDocumentId = Long.parseLong(request.getParameter("id"));
AnnouncementMgrBD announcementMgrBD = new AnnouncementMgrBD();
AnnoAttachDocument annoAttachDocument = announcementMgrBD.getAnnoAttachDocumentById(annoAttachDocumentId);
DocumentResp documentResp = announcementMgrBD.downloadAnnoAttachDocument(annoAttachDocumentId);
String fileExt = documentResp.getCachePath().substring(documentResp.getCachePath().lastIndexOf(".")+1);
ByteArrayInputStream inputStream = documentResp.getDocContent();
byte[] bAr = new byte[documentResp.getDocContent().available()];
if(fileExt.equals("pdf")){
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline");
}else{
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename="+annoAttachDocument.getDocName());
}
inputStream.read(bAr);
inputStream.close();
response.setContentLength(bAr.length);
FileCopyUtils.copy(bAr, response.getOutputStream());
return null;
}
下一篇: boolean类型格式化问题
推荐阅读
-
document.getElementsByName和document.getElementById 在IE与FF中不同实现
-
AJAX的进阶使用(Blob、ArrayBuffer、FormDate、Document、JSON、Text)-javascript-lNong-SegmentFault思否
-
JS 的 Document对象
-
用Document Imaging轻松把图片上的文字转成word文字
-
jQuery获取iframe的document对象的方法教程
-
在文档加载后使用(document./write),会覆盖整个文档的原因是什么
-
JQ中$(window).load和$(document).ready区别与执行顺序
-
[BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+
-
C# extract img url from web content then download the img
-
jquery中的$(document).ready()使用小结