Struts2中的配置文件
   <result name="fwjcprint" type="jasper">
               <param name="location">/jasper/fwjcdReport.jasper</param>
               <param name="format">HTML</param>
               <param name="dataSource">bcpjcdVoList</param>
    </result>两个JAVABEAN
//主表的数据源
public class BcpjcdVo{
private String jcdid;
......
List<BcpjcdmxVo> bcpjcdmxList;.....}//子报表的数据源
public class BcpjcdmxVo{
private String mxid;
private String bcpmc;
.....}Action 里的方法
public String printUI(){
......
String jcdid = ServletActionContext.getRequest().getParameter("jcdid");
BcpjcdVo jcdVo = fwjcdDaoJDBC.queryBcpjcdByJcdid(jcdid);
List<BcpjcdmxVo> bcpjcdmxVo = fwjcdDaoJDBC.queryBcpjcdMxByJcdid(jcdid);

ServletActionContext.getRequest().setAttribute("jcdmxList", bcpjcdmxVo );
jcdVo.setBcpjcdmxList(ycljcdmxVo);//当我设置时就会报错,不设时就没有问题

this.setBcpjcdVo(jcdVo);
......
return FWJCPRINT;
}
错误信息:java.lang.ClassCastException: org.apache.struts2.views.jasperreports.ValueStackDataSource cannot be cast to java.util.List这个问题困扰了几天了,我也在网上找过,但网上的都是简单的,请各位路过的大虾帮帮忙,分不是问题

解决方案 »

  1.   

    类别转换错误?需要一个java.util.List,传进去的却是org.apache.struts2.views.jasperreports.ValueStackDataSource
    没试过s2的.
      

  2.   

    实在不会,帮你找了个连接,你去看看吧.
    http://www.javaeye.com/problems/39668
      

  3.   

    呵呵,有点笨,用那个方法驰存在问题,现在用这种方法,但他有一个提示窗口,怎么样才能去掉
     HttpServletResponse resp = ServletActionContext.getResponse();
    String root_path = ServletActionContext.getServletContext().getRealPath("/");
    root_path = root_path.replace('\\', '/');
      list.add(jcdVo);
       
    String reportFilePath =  root_path + "jasper/fwjcdReport.jasper";;
    JRDataSource dataSource = new JRBeanCollectionDataSource(list); Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("SUBREPORT_DIR", root_path + "jasper/");
    JasperReport report = (JasperReport)JRLoader.loadObject(reportFilePath);
    JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
            OutputStream ouputStream = resp.getOutputStream();  
           resp.setContentType("application/html");
            resp.setCharacterEncoding("UTF-8");  
            resp.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode("PDF报表", "UTF-8") + ".html\"");    
            // 使用JRPdfExproter导出器导出pdf  
            //JRPdfExporter exporter = new JRPdfExporter();  
          JRHtmlExporter exporter = new JRHtmlExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);  
          exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, root_path+"images/");
      

  4.   

    用ireport4 怎么制作子报表,网上没什么资料,全是老版的ireport