请教一下诸位,我使用ireport0.5.1生成的html格式是正常的
如下面网址所示
http://www.hyweb.net/Public/test1.mht但是当我试图使用jasperreports1.0.1从jsp/servlet中生成的时候
虽然数据依然正确,但是html的格式完全走样了,如下
http://www.hyweb.net/Public/test2.mht不知道空的那些图片是什么意思,我的jsp与servlet都是参照了
jasperreports中的demo代码,现贴出servlet中的代码,请大家参考帮忙public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {        ServletContext context = this.getServletConfig().getServletContext();        response.setContentType("text/html;charset=GB2312");
        PrintWriter out = response.getWriter();
        Connection conn = null;
        
        System.out.println("Ready to report File...");
        
        String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=swoa20";
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            conn = DriverManager.getConnection(url,"sa", "");
            
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
                try
        {
            File reportFile = new File(context.getRealPath("/report/hytest1.jasper"));
            if (!reportFile.exists())
                throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");            JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
        
            Map parameters = new HashMap();
                        
            JasperPrint jasperPrint = 
                JasperFillManager.fillReport(
                    jasperReport, 
                    parameters, 
                    conn
                    );
                        
            JRHtmlExporter exporter = new JRHtmlExporter();
        
            Map imagesMap = new HashMap();
            request.getSession().setAttribute("IMAGES_MAP", imagesMap);
            
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");
            
            exporter.exportReport();
        }
        catch (JRException e)
        {
            //错误处理... ...
        }    }

解决方案 »

  1.   

    目前我找到的问题是缺少一个pixel.GIF图片
    这个图片在jasper的jar包里面自带了的,但是图片里面找不到,没有办法,我只能将这几个文件拷贝出来放在jsp/servlet同级目录下,请问能不能指定IMAGES_URI呢,比如说指定到目录images下面,我没有找到对下面语句合适的修改方法。Map imagesMap = new HashMap();
    session.setAttribute("IMAGES_MAP", imagesMap);
    exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
    exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image.jsp?image=");
      

  2.   

    不是吧,一个回复都没有?what's wrong with CSDN?
      

  3.   

    IMAGES_URI是可以配置的,在JasperReports包里有个J2EE包里有个ImageServlet,在web.xml配置其映射即可