struts2 以报表输出的问题

struts2 spring hibernate3 eclipse3.3.2 相关问题

在做 报表输出的时候 把按照条件搜索出来的数据 以 PDF CSV的形式输出 出现如下错误:

下面给出部分代码:

model层存放的是hibernate 生成的与数据库对应的两个文件 这里不给出 给出 表的字段:

id  name  author publish  time isbn page content

dao层

public class EmpbookDaoImpl extends HibernateDaoSupport implements EmpbookDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Empbook> getEmpbook() {
		// TODO Auto-generated method stub
		String sql = "from Empbook empbook";
		List<Empbook> list = this.getHibernateTemplate().find(sql);
		return list;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List getQuery() {
		// TODO Auto-generated method stub
		String sql = "from Empbook empbook";
		List<Empbook> list = this.getHibernateTemplate().find(sql);
		return list;
	}

	

}

 

service 层

public class EmpbookServiceImpl implements EmpbookService {

	EmpbookDao empbookDao;
	@Override
	public List<Empbook> getEmpbook() {
		// TODO Auto-generated method stub
		return empbookDao.getEmpbook();
	}
	public EmpbookDao getEmpbookDao() {
		return empbookDao;
	}
	public void setEmpbookDao(EmpbookDao empbookDao) {
		this.empbookDao = empbookDao;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List getQuery() {
		// TODO Auto-generated method stub
		return empbookDao.getQuery();
	}

}

 
 action 层

public class EmpbookAction extends ActionSupport {

	EmpbookService empbookService;
//	Empbook Empbook;
	
	private String id;
	private String name;
	private String author;
	private String publish;
	private String time;
	private String isbn;
    private int page;
	private String content;
//get set 方法省略	
	private List<Empbook> availableItems;
	
	public String Display() throws Exception{
		
		Empbook p1 = new Empbook("sdf","asd","sds","sdsd","sds","ds",50,"sdf");
		Empbook p2 = new Empbook("wqe","www","sddss","sdadsd","swqewqds","dqwes",510,"sdfqwewq");
		Empbook p3 = new Empbook("qwe","awd","ssds","sdwqewqsd","swqewqeds","dqweqws",150,"swqewqdf");
	 availableItems = new ArrayList<Empbook>();
	 availableItems.add(p1);
	 availableItems.add(p2);
	 availableItems.add(p3);
	 try {
	      String reportSource;
	      reportSource=ServletActionContext.getServletContext().getRealPath("/jasper/jasper_template.jrxml");
	      File parent = new File(reportSource).getParentFile();
	      JasperCompileManager.compileReportToFile(reportSource,
	        new File(parent, "compiled_jasper_template.jasper").getAbsolutePath());
	    }catch (Exception e) {
	      e.printStackTrace();
	    }
	 return SUCCESS;
	}

 struts.xml

<action name="CSV" 
         class="com.myapp.struts2.action.EmpbookAction" method="Display">
        <result name="success">
          <param name="location">/jasper/compiled_jasper_template.jasper</param>
          <param name="dataSource">availableItems</param>
          <param name="format">CSV</param>
        </result>
      </action>
      <action name="PDF" 
             class="com.myapp.struts2.action.EmpbookAction" method="Display">
        <result name="success">
          <param name="location">/jasper/compiled_jasper_template.jasper</param>
          <param name="dataSource">availableItems</param>
          <param name="format">PDF</param>
        </result>
      </action>

 jsp

<tr>
<td>
    <select name="fieldname" >
        <option value="gameNameCn">中文名称</option>
        <option value="gameNameEn">英文名称</option>
        <option value="gameCapacity">碟数</option>
        <option value="gameVersion">版本</option>
        <option value="gameMedia">介质</option>
        <option value="gameCopyright">版权</option>
    </select>
    <input value="" name="value"  />
<a href="#" onclick="btnQuery()">查询</a>
<br><a href="CSV.action">CSV</a>
<br><a href="PDF.action">PDF</a>

</tr>

</table>
 
</s:form>
</body>

 

jasper_template.jrxml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="jasper_test">
<!-- our fields -->
<field name="id" class="java.lang.String" />
<field name="name" class="java.lang.String" />
<field name="author" class="java.lang.String" />
<field name="publish" class="java.lang.String" />
<field name="time" class="java.lang.String" />
<field name="isbn" class="java.lang.String" />
<field name="page" class="java.lang.String" />
<field name="content" class="java.lang.String" />
<title>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="180" height="15" />
<textElement />
<text>
<![CDATA[Struts2 JasperReports Sample]]>
</text>
</staticText>
</band>
</title>
<pageHeader>
<band></band>
</pageHeader>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Id]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Name]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Author]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Publish]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Time]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Isbn]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Page]]>
</text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20" />
<textElement>
<font isUnderline="true" />
</textElement>
<text>
<![CDATA[Content]]>
</text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{id}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{author}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{publish}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{time}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{isbn}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{page}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="360" y="0" width="180" height="15" />
<textElement />
<textFieldExpression>
<![CDATA[$F{content}]]>
</textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band></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></band>
</summary>
</jasperReport>

 

错误如下:

2008/07/01 15:13:34 org.apache.catalina.core.StandardWrapperValve invoke
致命的: サーブレット default のServlet.service()が例外を投げました
java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:116)
	at com.myapp.struts2.action.EmpbookAction.Display(EmpbookAction.java:77)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
	at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Unknown Source)

 请帮帮忙 着急要结果

 

如果是 多个表 a b c 相关联 按照多个条件进行检索 把结果在jsp 显示出来 并以 PSD CSV 形式输出 数据是从数据库中查询得到的 应该如何修改呢?

你可能感兴趣的:(java,apache,sql,F#,360)