我正在开发一个 struts2 应用程序,我想在浏览器上显示我生成的报告。我已经成功地在磁盘上生成了我的报告。但现在我想在浏览器上看到它。这里有一些代码。
我的 index.jsp
<body>
<a href="HTML.action">Reporting</a>
</body>
我的动作 DataBeanList
public class DataBeanList extends ActionSupport {
public ArrayList<DataBean> getDataBeanList() {
ArrayList<DataBean> dataBeanList = new ArrayList<DataBean>();
dataBeanList.add(produce("Manisha", "India"));
dataBeanList.add(produce("Dennis Ritchie", "USA"));
dataBeanList.add(produce("V.Anand", "India"));
dataBeanList.add(produce("Shrinath", "California"));
dataBeanList.add(produce("issam", "casa"));
return dataBeanList;
}
/**
* This method returns a DataBean object,
* with name and country set in it.
*/
private DataBean produce(String name, String country) {
DataBean dataBean = new DataBean();
dataBean.setName(name);
dataBean.setCountry(country);
return dataBean;
}
public void exporte(){
String sourceFileName = "D://Test/workspace/ztest/WebContent/reports/jasper_report_template.jasper";
// + "test/jasper_report_template.jasper";
//D:\Test\workspace\ztest\WebContent\reports
String printFileName = null;
DataBeanList DataBeanList = new DataBeanList();
ArrayList dataList = DataBeanList.getDataBeanList();
JRBeanCollectionDataSource beanColDataSource =
new JRBeanCollectionDataSource(dataList);
Map parameters = new HashMap();
try {
printFileName = JasperFillManager.fillReportToFile(sourceFileName,
parameters, beanColDataSource);
if (printFileName != null) {
/**
* 1- export to PDF
*/
JasperExportManager.exportReportToPdfFile(printFileName,
"D://sample_report.pdf");
}
} catch (JRException e) {
e.printStackTrace();
}
}
}