display标签的使用t required libraries are missing: com/lowagie/text/Element

近期在我的项目中使用了display标签,原本以为特别容易,用起来就有错了:

在使用display标签的时候后台报错如下:

2011-03-22 19:03:47,224 org.displaytag.export.ExportViewFactory.<init>(ExportViewFactory.java:61) INFO [org.displaytag.export.ExportViewFactory] - <Initializing ExportViewFactory with type={csv,excel,xml,pdf,rtf}>

2011-03-22 19:03:47,268 org.displaytag.export.ExportViewFactory.registerExportView(ExportViewFactory.java:105) WARN [org.displaytag.export.ExportViewFactory] - <Unable to instantiate class for pdf export. org.displaytag.export.PdfView was found, but required libraries are missing: com/lowagie/text/Element>

2011-03-22 19:03:47,302 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704) ERROR [StandardWrapper[/tyut:jsp]] - <Servlet.service() for servlet jsp threw exception>

java.lang.NullPointerException

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at org.displaytag.util.ReflectHelper.classForName(ReflectHelper.java:43)

at org.displaytag.export.ExportViewFactory.registerExportView(ExportViewFactory.java:95)

at org.displaytag.export.JspServlet.service(JspServlet.java:241)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

经过查看官方文档,知道:

     If you would like to make use of the display taglib in your own application, do the following:

  1. Drop the displaytag-version.jar file in your application WEB-INF/lib directory
  2. Make sure that following libraries are in your WEB-INF/lib directory (or made available via the classpath to your application server). Refer to the dependencies document for the correct version of these libraries. You can download a copy of everything from jakarta or you can grab them from the example webapp in the bin distribution. The following is the list of dependencies:
    • commons-logging
    • commons-lang
    • commons-collections
    • commons-beanutils
    • log4j
    • itext (optional, for pdf/rtf export)

    You may want to include also the displaytag-export-poi jar, which adds an excel binary export using jakarta POI. The poi jar is required by displaytag-export-poi

  3. Optional. Depending on your architecture, you may need to configure a filter to make export work. See the export filter page for the details about how to do it and when you could need it. 缺少itext.jar就会报上面的错。所以我加了itext-1.4.jar,重新启动项目,ok