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

          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文件就打不開了,會出現“file is damaged”的提示信息。

          如果把第3行換成:

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


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

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

          主站蜘蛛池模板: 乳源| 嵩明县| 平湖市| 宜城市| 泸溪县| 汕尾市| 循化| 渑池县| 高雄市| 兴城市| 安吉县| 彭泽县| 商河县| 宁安市| 吴江市| 漠河县| 清水河县| 维西| 湖州市| 永济市| 石柱| 温泉县| 平乐县| 安溪县| 温宿县| 嵩明县| 河津市| 上林县| 肇源县| 合江县| 大庆市| 武冈市| 菏泽市| 墨江| 深州市| 苍山县| 东乡族自治县| 夏河县| 合水县| 定州市| 西乌珠穆沁旗|