JSP+SERVLET中使用JFREEREPORT问题
我的servlet是这样的:
package com.test;
import
java.io.IOException;
import java.io.OutputStream;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.report.JFreeReport;
import org.jfree.report.modules.output.table.base.TableProcessor;
import org.jfree.report.modules.output.table.html.HtmlProcessor;
import org.jfree.report.modules.output.table.html.StreamHtmlFilesystem;
import org.jfree.report.util.Log;
/**
* HtmlExampleServlet演示如何通过HTML表格在Web环境下展示JFreeReport定义的表格
*/
public class HtmlExampleServlet extends HttpServlet {
public void doGet(final HttpServletRequest request,
final HttpServletResponse response) throws
ServletException,
IOException {
doPost(request, response);
}
public void doPost(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
TableProcessor worker;
// 设置输出页面的Meta信息
response.setHeader( "Content-Disposition ", "inline; filename=\ " "
+ "unknown.html " + "\ " ");
// 设置页面的输出格式
response.setHeader( "Content-Type ", "text/html ");
try {
// 获取Servlet的输出流
OutputStream out = response.getOutputStream();
// 获取HelloWorld中定义的报表
HelloWorld helloWorld = new HelloWorld();
JFreeReport report = helloWorld.getReport();
// 将报表和Servlet的输出流作为参数传递给TableProcessor的实例
final HtmlProcessor processor = new HtmlProcessor(report);
processor.setFilesystem(new StreamHtmlFilesystem(out));
worker = processor;
} catch (Exception e) {
Log.debug( "无法解析报表定义 ", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
try {
// 输出结果
worker.processReport();
} catch (Exception e) {
Log.debug( "输出结果产生错误 ", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
}
web.xml是这样的:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name> Rtest </servlet-name>
<servlet-class> com.test.HtmlExampleServlet </servlet-class&