私の悪い英語でごめんなさい。私はGAE+GWTでiTextを使用しています。サンプルアプリを作成しましたが、Googleで動作します。しかし、URLのトークンに問題があります。
私はこのRPCサービスを持っており、バイト配列でドキュメントを作成し、これをHttpSessionに書き込みます。次に、クライアントonSuccessブロックで、クライアントにPDFを送信するサーブレットを呼び出します。これString token = "258958395ai53"
は、クライアントがPDFを見つけるトークンですが、この例では、トークンを静的にしたので、トークンをランダムに作成し、トークンが繰り返されないようにする必要があります。これがコードです。
RPCサービス:
public String getPdf() {
Document document = new Document();
String token = "258958395ai53";
// generate test PDF
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("¡HOLA PUTO MUNDO!"));
document.close();
byte[] pdf = baos.toByteArray();
HttpServletRequest request = this.getThreadLocalRequest();
HttpSession session = request.getSession();
session.setAttribute(token, pdf);
} catch (Exception e) {
System.out.println("ReportServlet::generatePDF::Exception "
+ e.getMessage());
}
return token;
}
サーブレット:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// create output stream from byte array in session
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String token = request.getParameter("token");
byte[] pdf = (byte[]) request.getSession().getAttribute(token);
baos.write(pdf);
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0,pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
// content length is needed for MSIE
response.setContentLength(baos.size());
// write ByteArrayOutputStream to ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
out.close();
}
onSuccess:
public void onSuccess(String lista) {
String token = lista;
//Window.open("hello?token="+ token, "_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
Dialog d = new Dialog();
d.setWidth(500);
d.setHeight(700);
d.setUrl(GWT.getModuleBaseURL()+"hello?token="+token);
d.show();
}
});
何か案が?..私の例を見ることができますhttp://pdfprueba2.appspot.com/