iText不能正常输出,高气给点主意吧!
下而代码输出的只是一个空白页,是不是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() {
}
}