首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

WebOffice 开发文档-code

2012-10-24 
WebOffice 开发文档--code/** * 初始化附件编辑页面 */private void initOnlineEdit(HttpServletRequest r

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);}}}

热点排行