【发布时间】:2019-09-23 18:55:18
【问题描述】:
我正在使用 java 并从数据库创建一个 pdf 文件。 现在我想让它自动为用户下载。 当用户点击该 servlet 页面时。 这是我的一些代码...
/* Define the SQL query */
ResultSet rs=st.executeQuery("select Id,Name from student");
Document my_pdf_report = new Document();
my_pdf_report.open();
//we have four columns in our table
PdfPTable my_report_table = new PdfPTable(2);
//create a cell object
PdfPCell table_cell;
while (rs.next()) {
String id = rs.getString("Id");
table_cell=new PdfPCell(new Phrase(id));
my_report_table.addCell(table_cell);
String name=rs.getString("Name");
table_cell=new PdfPCell(new Phrase(name));
}
/* Attach report table to PDF */
my_pdf_report.add(my_report_table);
Document pdf =new Document();
pdf=my_pdf_report;
my_pdf_report.close();
/* Close all DB related objects */
rs.close();
st.close();
connected.close();
【问题讨论】:
标签: java file servlets document