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

          Web application 中使用Crystal Report(二)

          Posted on 2007-04-13 22:31 馬達+斯加 閱讀(616) 評論(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文件就打不開了,會出現(xiàn)“file is damaged”的提示信息。

          如果把第3行換成:

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


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

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

          主站蜘蛛池模板: 崇义县| 张家界市| 临颍县| 博爱县| 许昌县| 汾西县| 雷州市| 礼泉县| 保定市| 泗洪县| 乐平市| 枝江市| 邵阳市| 屯门区| 察哈| 拉孜县| 白朗县| 班戈县| 巫山县| 蒲江县| 梓潼县| 隆安县| 大田县| 调兵山市| 延津县| 东乌珠穆沁旗| 安徽省| 葵青区| 耒阳市| 赤峰市| 长寿区| 鸡泽县| 安阳市| 开远市| 迁安市| 霞浦县| 济宁市| 正安县| 昆明市| 台北市| 迁西县|