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

dhzsir dhzsir 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下而代码输出的只是一个空白页,是不是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() {
}
}
...全文
评论 1
收藏 已收藏
分享
返回顶部
dhzsir
Java SE 62,620 成员 307,251 内容