posts - 84, comments - 54, trackbacks - 0, articles - 0
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Web application 中使用Crystal Report(二)

          Posted on 2007-04-13 22:31 馬達+斯加 閱讀(613) 評論(0)  編輯  收藏 所屬分類: Java Report
           

          無論Crystal report,還是Jasper Report,一到了Websphere Portal中總是要折騰一番才能出來的。

          首先,CR的標簽到了portlet中就出錯了,“This method can be called after HTTP body”,好像是這個信息。

          其次,如果使用 viewer.processHttpRequest() 也會出錯。

          再有,不能在Jsp中使用<portlet:defineObjects />,否則也會報錯。

          諸多問題,也沒有深入去研究,最簡單的解決辦法就是使用普通的jsp文件來生成報表,然后用iframe將這個jsp包含在portlet中

          順便也談談Jasper Report吧,雖然也很容易使用,但是到了Portal里面也不同了。

          以導出PDF文件為例子,一般的代碼塊如下:

          HttpServletResponse httpServletResponse = (HttpServletResponse) portletResponse;
          httpServletResponse.setContentType(
          "application/pdf");
          S ervletOutputStream outputStream 
          = httpServletResponse.getOutputStream();

          InputStream inputStream 
          = this.getServlet().getServletConfig().getServletContext().getResourceAsStream("/ rpt/Flights.jasper");

          JRBeanCollectionDataSource beanDataSource 
          = new JRBeanCollectionDataSource(filghts); //'flights' is a pre-defined arraylist contains all records to be printed

          //Export PDF file
          JasperRunManager.runReportToPdfStream(inputStream, outputStream, new HashMap(), beanDataSource);
          outputStream.flush();
          outputStream.close();


          這在普通web應用中沒有任何問題,但是,到了portal里面,導出的PDF文件就打不開了,會出現“file is damaged”的提示信息。

          如果把第3行換成:

          FileOutputStream outputStream = new FileOutputStream(new File("C:\\report.pdf"));


          導出的PDF就不會有問題。使用ultraedit比較了兩個導出的PDF后發現,使用servletOutputStream的那個,在EOF后多出了一長串portal頁面的HTML代碼出來,難怪打不開了。

          解決辦法就是使用普通的servlet而不用portlet servlet。

          主站蜘蛛池模板: 安徽省| 霍邱县| 广平县| 浦北县| 西乌珠穆沁旗| 泗洪县| 潮安县| 新乐市| 图木舒克市| 辽源市| 开鲁县| 泽库县| 长顺县| 长寿区| 德州市| 合肥市| 南开区| 尉氏县| 通化县| 雷山县| 化德县| 广元市| 七台河市| 论坛| 平远县| 大港区| 开原市| 老河口市| 合作市| 寿阳县| 舟山市| 青冈县| 文昌市| 娄底市| 类乌齐县| 合江县| 曲阜市| 靖安县| 营口市| 太保市| 共和县|