/**
* 初始化附件编辑页面
*/
private void initOnlineEdit(HttpServletRequest request,
HttpServletResponse response, AttachmentVO attachment, String uploadPath)
throws ApplicationException {
FileInputStream fileInputStream = null;
BufferedInputStream bufferedInputStream = null;
BufferedOutputStream bufferedOutputStream = null;
try {
// 获取输入输出流
fileInputStream = new FileInputStream(new File(uploadPath));
bufferedInputStream = new BufferedInputStream(fileInputStream);
bufferedOutputStream = new BufferedOutputStream(response
.getOutputStream());
response.setContentType("application/x-download");
response.setHeader("Content-disposition", "attachment; filename="
+ attachment.getOverview());
byte[] buffer = new byte[1024];
int readBytes = 0;
while ((readBytes = bufferedInputStream.read(buffer, 0,
buffer.length)) != -1) {
bufferedOutputStream.write(buffer, 0, readBytes);
}
bufferedOutputStream.flush();
} catch (IOException e) {
throw new ApplicationException(e);
} catch (Exception e) {
throw new ApplicationException(e);
} finally {
try {
fileInputStream.close();
bufferedInputStream.close();
bufferedOutputStream.close();
} catch (IOException e) {
throw new ApplicationException(e);
}
}
}
/**
* 编辑后上传处理
*/
private int uploadAttachment(HttpServletRequest request,
HttpServletResponse response, AttachmentVO attachment, String dir) throws ApplicationException {
// 获取上传路径
String uploadPath = dir + File.separator + attachment.getImageUrl()
+ File.separator;
try {
PageContext pageContext = JspFactory.getDefaultFactory()
.getPageContext(this.getServlet(), request, response, null,
true, 8192, true);
SmartUpload smartUpload = new SmartUpload();
smartUpload.initialize(pageContext);
smartUpload.upload();
return smartUpload.save(uploadPath);
} catch (ServletException e) {
throw new ApplicationException(e);
} catch (SmartUploadException e) {
throw new ApplicationException(e);
} catch (IOException e) {
throw new ApplicationException(e);
}
}
}
WebOffice 开发文档--code
最新推荐文章于 2021-10-28 19:44:31 发布