我想将jasper报告集成到我的struts 2应用程序中。
但是我遇到了这个异常:
java.lang.NullPointerException
net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
org.apache.struts2.views.jasperreports.JasperReportsResult.doExecute(JasperReportsResult.java:325)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
interceptor.LoginInterceptor.intercept(LoginInterceptor.java:40)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
我添加的罐子
struts 2核心2.3.15
碧玉报告3.1.2
公地lang 3.2
共用消化池1.7
公地beanutils 1.7.0
公地收藏2.1
常用日志记录1.0
struts2碧玉报表插件2.3.15
乔达时间2.1.0
这是报告文件。
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
pageWidth="595" pageHeight="842" columnWidth="555"
leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"
name="our_jasper_template">
<property name="ireport.zoom" value="1.0" />
<property name="ireport.x" value="0" />
<property name="ireport.y" value="0" />
<field name="customerName" class="java.lang.String"/>
<field name="customerId" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" >
</band>
</title>
<pageHeader>
<band height="50">
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="552"
height="35" backcolor="#CCCCCC" />
<textElement textAlignment="Center">
<font size="26" />
</textElement>
<text><![CDATA[user Report]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band/>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textFieldExpression><![CDATA[$F{customerName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textFieldExpression><![CDATA[$F{customerId}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="40" height="15"/>
<textElement/>
<text><![CDATA[Page:]]></text>
</staticText>
<textField>
<reportElement x="40" y="0" width="100" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
动作类
public class TestJasperAction extends ActionSupport {
List<PolicyBean> beanCollection=new ArrayList();
@Override
public String execute() {
ResultSet rs = PolicyDao.getPolicyRsTest();
try {
while (rs.next()) {
PolicyBean p = new PolicyBean();
p.setCustomerName(rs.getString("customer_first_name") + " " + rs.getString("customer_last_name"));
p.setCustomerId(rs.getString("customer_no"));
beanCollection.add(p);
}
} catch (SQLException ex) {
Logger.getLogger(TestJasperAction.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Bean size:"+beanCollection.size());
return SUCCESS;
}
public List<PolicyBean> getBeanCollection() {
return beanCollection;
}
public void setBeanCollection(List<PolicyBean> beanCollection) {
this.beanCollection = beanCollection;
}
}
struts.xml
<action name="JasperTesting" class="action.TestJasperAction">
<result name="success" type="jasper">
<param name="location">/iacms/jaspers/our_jasper_template.jasper</param>
<param name="dataSource">beanCollection</param>
<param name="format">PDF</param>
</result>
JSP代码:
<div class="form-group row" style="margin-left: 250px">
<s:form action="JasperTesting">
<s:submit cssClass="btn btn-success" value="Generate Report"/>
</s:form>
</div>
任何帮助或指导将不胜感激。