私は授業のためにJava Webアプリケーションをやっています。このアプリケーションには、売り手と買い手の 2 種類のユーザーがいます。バイヤーは一連のものを購入することができます。彼が購入した場合、領収書を PDF 形式で作成する必要があります。しかし、Tomcat で何かを購入しようとすると、次のエラーが表示されます。
HTTP Status 500 - \WebApplication\pdf\test.pdf (Impossibile trovare il percorso specificato)
type Exception report
message \WebApplication\pdf\test.pdf (Impossibile trovare il percorso specificato)
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.io.FileNotFoundException: \WebApplication\pdf\test.pdf (Impossibile trovare il percorso specificato)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:212)
java.io.FileOutputStream.<init>(FileOutputStream.java:104)
viewer.PdfCreator.createPdf(PdfCreator.java:30)
servlet.BuyerConfirmationPage.doGet(BuyerConfirmationPage.java:115)
servlet.BuyerConfirmationPage.doPost(BuyerConfirmationPage.java:61)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
そして、ここに私が書いたコードがあります:
try {
Document document = new Document(PageSize.A4,50,50,50,50);
PdfWriter.getInstance(document,new FileOutputStream(request.getContextPath() + "/pdf/test.pdf"));
document.open();
PdfPTable table = new PdfPTable(5);
PdfPCell seller_cell = new PdfPCell(new Paragraph("Seller"));
PdfPCell name_cell = new PdfPCell(new Paragraph("Name"));
PdfPCell price_cell = new PdfPCell(new Paragraph("Price"));
PdfPCell UM_cell = new PdfPCell(new Paragraph("UM"));
PdfPCell quantity_cell = new PdfPCell(new Paragraph("Quantity"));
table.addCell(seller_cell);
table.addCell(name_cell);
table.addCell(price_cell);
table.addCell(UM_cell);
table.addCell(quantity_cell);
PdfPCell seller_cell_value = new PdfPCell(new Paragraph(seller));
PdfPCell name_cell_value = new PdfPCell(new Paragraph(name));
PdfPCell price_cell_value = new PdfPCell(new Paragraph(total_price));
PdfPCell UM_cell_value = new PdfPCell(new Paragraph(UM));
PdfPCell quantity_cell_value = new PdfPCell(new Paragraph(quantity));
table.addCell(seller_cell_value);
table.addCell(name_cell_value);
table.addCell(price_cell_value);
table.addCell(UM_cell_value);
table.addCell(quantity_cell_value);
document.add(table);
document.close();
} catch (DocumentException ex) {
Logger.getLogger(PdfCreator.class.getName()).log(Level.SEVERE, null, ex);
}
コードが正しく、フォルダーが存在することは確かですが、ファイルを保存できないのはなぜですか?