JasperReport 使用JavaBean最为数据源出错,请高手解答!
我是按照JasperReport for Java Developers.pdf来做的
public class FirstReportAction extends DispatchAction {
private JRDateSource createReportDataSource() {
JRBeanCollectionDataSource dataSource;
Collection reportRows=initlializeBeanCollection();
dataSource=new JRBeanCollectionDataSource(reportRows);
return dataSource;
}
@SuppressWarnings("unchecked")
private Collection initlializeBeanCollection(){
ArrayList reportRows=new ArrayList();
reportRows.add(new OuserBO("1","2","3"));
return reportRows;
}
@SuppressWarnings("unchecked")
public ActionForward first(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
IOException {
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream reportStream = this.getServlet().getServletConfig().getServletContext()
.getResourceAsStream("/reports/ka.jasper");
try
{
JRDateSource dataSource=createReportDataSource();
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream,new HashMap
(),dataSource);
servletOutputStream.flush();
servletOutputStream.close();
}
错误:
private JRDateSource createReportDataSource()行报错如下:
JRDateSource
cannot be resolved to a type
JRDateSource dataSource=createReportDataSource()行报错如下
JRDateSource cannot be resolved to a type
The method createReportDataSource() is undefined for the type FirstReportAction
请问是什么原因?
------解决方案--------------------createReportDataSource() is undefined
方法没有定义啊,复制别人的代码而不理解是永远学不好JAVA的.
------解决方案--------------------有没有导入包啊?
import
net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;