私は Java で書いていますが、ユーザーのために動的な HTML ページを作成したいと考えています。Lowagie を使用して HTML でドキュメントを作成しています。html を表示することはできますが、私の画像は空です。それはちょうど絵の境界線を含んでいます。誰でもこれで私を助けることができますか?または、HTML ページを作成する別の方法を教えてください (ByteArrauOutputstream または他の出力ストリームを使用してコンテンツを表示することをお勧めします)。
コードは次のとおりです。
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String orderId = request.getParameter("id1");
String telephone = request.getParameter("id2");
response.setHeader("Expires", EXPIRES);
response.setContentType(CONTENT_TYPE);
ServletOutputStream out = null;
ByteArrayOutputStream baos = null;
try {
baos = getHtmlTicket(orderId, telephone);
response.setContentLength(baos.size());
out = response.getOutputStream();
baos.writeTo(out);
}
catch (Exception e) {
log.error(e.getMessage(), e);
}
finally {
if (out != null) {
try {
out.flush();
}
catch (Exception e) {
log.debug(e.getMessage(), e);
}
}
if (baos != null) {
try {
baos.flush();
}
catch (Exception e) {
log.debug(e.getMessage(), e);
}
}
if (out != null) {
try {
out.close();
}
catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
if (baos != null) {
try {
baos.close();
}
catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
}
public ByteArrayOutputStream getHtmlTicket(String orderId, String telephoneTest) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
Order order = orderService.getOrder(Integer.parseInt(orderId));
String fileType = "png";
String filePath = "html/picture.png";
File myFile = new File(filePath);
try {
HtmlWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World"));
Image fileImage = Image.getInstance(filePath);
document.add(fileImage);
document.add(new Paragraph("osv"));
}
catch (DocumentException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
document.close();
return baos;
}