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

          無(wú)論Crystal report,還是Jasper Report,一到了Websphere Portal中總是要折騰一番才能出來(lái)的。

          首先,CR的標(biāo)簽到了portlet中就出錯(cuò)了,“This method can be called after HTTP body”,好像是這個(gè)信息。

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

          再有,不能在Jsp中使用<portlet:defineObjects />,否則也會(huì)報(bào)錯(cuò)。

          諸多問(wèn)題,也沒(méi)有深入去研究,最簡(jiǎn)單的解決辦法就是使用普通的jsp文件來(lái)生成報(bào)表,然后用iframe將這個(gè)jsp包含在portlet中

          順便也談?wù)?/span>Jasper Report吧,雖然也很容易使用,但是到了Portal里面也不同了。

          以導(dǎo)出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應(yīng)用中沒(méi)有任何問(wèn)題,但是,到了portal里面,導(dǎo)出的PDF文件就打不開(kāi)了,會(huì)出現(xiàn)“file is damaged”的提示信息。

          如果把第3行換成:

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


          導(dǎo)出的PDF就不會(huì)有問(wèn)題。使用ultraedit比較了兩個(gè)導(dǎo)出的PDF后發(fā)現(xiàn),使用servletOutputStream的那個(gè),在EOF后多出了一長(zhǎng)串portal頁(yè)面的HTML代碼出來(lái),難怪打不開(kāi)了。

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

          主站蜘蛛池模板: 陵川县| 乌兰县| 惠水县| 昌江| 大庆市| 武邑县| 合水县| 屯门区| 八宿县| 攀枝花市| 达日县| 合阳县| 望江县| 河北省| 兴文县| 驻马店市| 内丘县| 沈丘县| 静宁县| 乐昌市| 宜兰市| 余姚市| 永兴县| 华亭县| 巴楚县| 蒲城县| 台湾省| 塔河县| 苏尼特左旗| 平南县| 眉山市| 广丰县| 临澧县| 宁乡县| 平阳县| 大厂| 利川市| 乌拉特后旗| 华阴市| 鱼台县| 繁昌县|