日期:2014-05-17  浏览次数:20645 次

Struts2整合JasperReport输出HTML显示图片问题
我用的是struts2.0.11,iReport3.6.7
struts2整合JasperReport参考:http://www.blogjava.net/sterning/archive/2008/01/02/172317.html

按照一下方法解决我没有成功:(在浏览器上显示有很多红色XX)

1.web.xml配置
   <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>
2.配置成struts.action.extends=action
3.在WebRoot建立一个images文件夹,放入px文件
若要显示自己在报表中定义的图片,再加上红色部分
<action name="HTMLReport"  class="reportAction">
<result type="jasper">
<param name="location">/jasper/report.jasper</param>
<param name="format">HTML</param>
<param name="reportParameters">map</param>
<param name="dataSource">funList</param>
<param name="imageServletUrl"><![CDATA[/image?image=]]></param>
</result>
</action>

用重写JasperReportsResult.java中的doExcute()方法
@SuppressWarnings({ "unchecked", "deprecation" })
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
        if (this.format == null) {
            this.format = FORMAT_PDF;
        }

        if (dataSource == null) {
            String message = "No dataSource specified...";
            LOG.error(message);
            throw new RuntimeException(message);
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating JasperReport for dataSource = " + dataSource + ", format = " + this.format);
        }

        HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
        HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(ServletActionContext.HTTP_RESPONSE);

        //construct the data source for the report
        ValueStack stack = invocation.getStack();
        ValueStackDataSource stackDataSource = new ValueStackDataSource(stack, dataSource);

        format = conditionalParse(format, invocation);
        dataSource = conditionalParse(dataSource, invocation);

        if (contentDisposition != null) {
            contentDisposition = conditionalParse(contentDisposition, invocation);
        }

&nb