iText不能正常输出,高气给点主意吧!

dhzsir 2003-03-26 12:39:35
下而代码输出的只是一个空白页,是不是WEB.XML需要配置,因为代码不什有问题的(从iText DOWN的)

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class OutSimplePDF extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String msg = (String)request.getParameter("msg");
if (msg == null || msg.trim().length() <= 0)
msg = "[ specify a message in the 'msg' argument on the URL ]";

// create simple doc and write to a ByteArrayOutputStream
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph(msg));
document.close();

// write ByteArrayOutputStream to the ServletOutputStream
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
}
catch (Exception e2) {
System.out.println("Error in "+getClass().getName()+"\n"+e2);
}
}
public void destroy() {
}
}
...全文
24 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhzsir 2003-03-26
  • 打赏
  • 举报
回复
g z

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧