2012-01-17 9 views
0

私はspringMVC WebサイトにJasperReportsを統合しました。 ローカルシステムで正常に動作していましたが、そのWebサイトをサーバーにアップロードするとレポートが生成されますが、ローカルシステムではポップアップしていません。私はまた、レポートのパスを変更するウェブサイトをアップロードする前にSpring MVCアプリケーションでJasperReportsレポートがポップアップしない

iReportは4.1を使用してい

。 レポートは宛先フォルダで生成されますが、自動的には表示されません。

これは私のコードです:あなたは絶対path.Iを使用している理由

jasperReport = JasperCompileManager.compileReport("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.jrxml"); 
//JasperFillManager.fillReportToFile("D:\\reports\\test.jasper", jasperParameter, rsss); 
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, rsss); 
//JasperPrintManager.printReport(jasperPrint,true); 

JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf"); 
//  new mainpage(getTitle()); 

if ((new File("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf")).exists()) { 
    Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf"); 
    p.waitFor(); 
+0

このコードは、サーバー上で実行されるのを助けるかもしれません。このコードを待っているもの: 'Process p = Runtime.getRuntime()。exec(" rundll32 url.dll、FileProtocolHandler C:\\ AttendanceReport.pdf ");'? –

+0

ところで、 'iReport'はJasperReportsのGUIレポートのテンプレートデザイナーです。 –

+0

ya私は知っているが、私はRuntime.getRuntime()。exec( "rundll32 url.dll、FileProtocolHandler C:\\ AttendanceReport.pdf");それ自体はサーバー上で実行されていません。レポートが生成されていることを確認しましたが、フォームがコードを公開していません。 – Raj

答えて

1

まず、あなたは相対パス(にServletContext.getRealPathを())を使用すべきだと思います。 第二には、それがHTTPたServletResponseにブラウザ書き込みPDFでレポートを表示ofcourse.For Webブラウザに表示し、それに応じてHTTPヘッダーを設定しません。このコード

Process p = Runtime 
     .getRuntime() 
     .exec("rundll32 url.dll,FileProtocolHandler C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\CallCenterRev\\reports\\AttendanceReport.pdf"); 
    p.waitFor(); 

何のためにあるのです。 uは、スプリング3を使用してrの場合

+0

このコードは指定された場所からファイルを開くためのものです。 生成されたpdfはこの場所に格納されていますので、ここでこのパスを指定しました。 – Raj

+0

今、私は自分のWebブラウザでそのpdfを開こうとしていますが、ここでは新しいタブで開きません。 – Raj

+0

rushikあなたはいくつかのブラウザとサーバーが別のマシンであると思っています。あなたはブラウザではなくサーバーにオープンpdfを書いてください。この例は、春のMVCでファイルをダウンロードする方法を示しています(http://snippets.dzone.com/posts/show/)。 4629) – ayengin

0

これは

@Controller 
    @RequestMapping(value="/report") 
    public class ReportsController 
    { 
     @RequestMapping(value="/getMyReport", method=RequestMethod.GET) 
     public void runReport(@RequestParam("someParam")String someParam,@RequestParam("someOtherParam")String someOtherParam,HttpServletRequest request,HttpServletResponse response) 
     { 
      InputStream is = null ; 
      is = request.getSession().getServletContext().getResourceAsStream("/WEB-INF/reports/myReport.jasper"); 
      Map paramMap = new HashMap(); 
      paramMap.put("someParam", someParam); 
      paramMap.put("someOtherParam", someOtherParam); 
      response.setContentType("application/pdf"); 
      response.setHeader("Content-Disposition", "inline; filename=myReport.pdf"); 
      try { 
       Connection connection =getDatabaseConnection();//let this method returns a database connection 
       JasperRunManager.runReportToPdfStream(is, response.getOutputStream(), paramMap, connection); 
       response.getOutputStream().flush(); 
       response.getOutputStream().close(); 
      } 
      catch (Exception e) 
      { 
       //may be some Exception handling 

      } 
     } 
    } 
+0

解決策を得ました。問題は私がwebcontentフォルダが生成されていないサーバー上にWARファイルを配備していたときでした。その後、そのフォルダフォームのパスを削除し、作業を開始しました.... – Raj

関連する問題