Struts2整合JasperReport的HTML圖形報表不顯示圖片問題的解決方案

來源:互聯網
上載者:User

今天,用iReport設計了一個圖形報表,然後整合到Web項目中,jar包都已經匯入了,也不拋異常,結果訪問HTML報表頁面的時候,圖形部分死活不顯示

經過摸索,終於找到瞭解決的辦法,詳細過程如下:

JasperReport版本為新版本4.6

匯出HTML顯示出現圖片不顯示的問題 ,需要先在web.xml中配置

<!-- JasperReport解決HTML顯示圖片不出來的問題 -->
 <servlet>  
    <servlet-name>JasperReportImageServlet</servlet-name>  
      <servlet-class>  
          net.sf.jasperreports.j2ee.servlets.ImageServlet  
     </servlet-class>  
 </servlet>  
 <servlet-mapping>  
    <servlet-name>JasperReportImageServlet</servlet-name>  
    <url-pattern>/image</url-pattern>  
</servlet-mapping>
然後在定義struts路徑的時候使用
<action name="test" class="SimpleJasperAction" method="execute">  
 <result name="success" type="jasper">  
     <param name="location">/jsp/report/test.jasper</param>  
     <param name="connection">jdbc</param>  
     <param name="format">HTML</param>  
     <param name="imageServletUrl">  
        <![CDATA[/image?image=]]>  
     </param>  
 </result>  

 </action> 

備忘:用iReport設計報表,使用jdbc作為資料來源,就不需要在程式中構造資料了


效果如下:



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.