WebOffice 开发文档--code


/**
* 初始化附件编辑页面
*/
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);
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值