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这个问题困扰了几天了,我也在网上找过,但网上的都是简单的,请各位路过的大虾帮帮忙,分不是问题
<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这个问题困扰了几天了,我也在网上找过,但网上的都是简单的,请各位路过的大虾帮帮忙,分不是问题
解决方案 »
- 【EXTJS】iframe里嵌套ext.window,怎样使ext.window弹出到iframe外
- 数据库如何在取出多条记录的时候都显示出来?
- 求struts+hibernate 项目,仅供学习用
- 谁给我看看这代码有什么问题???
- struts的一个ActionForm里面有个日期输入,怎么可以允许空呢?
- 问一个简单的关于打印的问题
- 用JSP写的客户函数,请问各位高手们能用VBScript调用吗?急急急10分钟给分!!!
- 怎么样把int类型赋值给String类型?
- 硬是笨得很啊!:(, 我一定要在javabean中用数组,可始终不行,兄弟姐妹,help me....,急,我在这等你们了:(
- jdbc连接数据库出错
- 100分求助org.springframework.beans.factory.BeanCreationException
- struts2 doubleselect 如何设置下拉列表的长度?doubleHeaderValue不好使啊,第二个下拉框不显示默认值!
没试过s2的.
http://www.javaeye.com/problems/39668
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/");