码迷,mamicode.com
首页 > 其他好文 > 详细

OAF 中下载使用XML Publisher下载PDF附件

时间:2015-07-21 12:31:17      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

OAF doesn‘t readily expose the Controller Servlet‘s HttpRequest and HttpResponse objects so you need to extract it from the OAPageContext object via:

HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();

Once you get the response object you could already manipulate its OutputStream.

public void downloadFile(OAPageContext pageContext) {
                                        
         HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
         
         File fileToDownload = this.createFile();
         
         String fileType = getMimeType("txt");
         response.setContentType(fileType);
         response.setContentLength((int) fileToDownload.length());
         response.setHeader("Content-Disposition", "attachment; filename=\"" + fileToDownload.getName() + "\"");

         InputStream in = null;
         ServletOutputStream outs = null;

         try {
         
             outs = response.getOutputStream();
             in = new BufferedInputStream(new FileInputStream(fileToDownload));
             int ch;
             
             while ((ch = in.read()) != -1) {
                 outs.write(ch);
             }

         } catch (IOException e) {
         
             // TODO
             e.printStackTrace();
             
         } finally {
         
             try {
             
                 outs.flush();
                 outs.close();
                 
                 if (in != null) {
                     in.close();
                 }
                 
             } catch (Exception e) {
             
                 e.printStackTrace();
                 
             }
             
         }
         
     }

 

 

参考资料:

Integrate XML Publisher and OA Framework

Downloading Files in OAF (需FQ)

XMLIntegrationCO

OAF 中下载使用XML Publisher下载PDF附件

标签:

原文地址:http://www.cnblogs.com/huanghongbo/p/4663757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!