public class StockReceiptReturnQuery extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String receiptNo = request.getParameter("ReceiptNo");
int Rno = Integer.parseInt(receiptNo);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "dinga");
PreparedStatement ps = con.prepareStatement("select * from project.stockreceiptreturn WHERE ReceiptNO =?");
ps.setInt(1, Rno);
out.print("<center><table width=25% border=1></center>");
out.print("<center><h1>StockReceiptReturnQuery:</h1></center>");
ResultSet rs = ps.executeQuery();
/* Printing column names */
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
out.print("<tr>");
out.print("<td>" + rsmd.getColumnName(1) + "</td>");
out.print("<td>" + rs.getInt(1) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(2) + "</td>");
out.print("<td>" + rs.getString(2) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(3) + "</td>");
out.print("<td>" + rs.getString(3) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(4) + "</td>");
out.print("<td>" + rs.getString(4) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(5) + "</td>");
out.print("<td>" + rs.getString(5) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(6) + "</td>");
out.print("<td>" + rs.getString(6) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(7) + "</td>");
out.print("<td>" + rs.getInt(7) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(8) + "</td>");
out.print("<td>" + rs.getInt(8) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(9) + "</td>");
out.print("<td>" + rs.getString(9) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(10) + "</td>");
out.print("<td>" + rs.getInt(10) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(11) + "</td>");
out.print("<td>" + rs.getString(11) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(12) + "</td>");
out.print("<td>" + rs.getDouble(12) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(13) + "</td>");
out.print("<td>" + rs.getDouble(13) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(14) + "</td>");
out.print("<td>" + rs.getInt(14) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(15) + "</td>");
out.print("<td>" + rs.getInt(15) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(16) + "</td>");
out.print("<td>" + rs.getDouble(16) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(17) + "</td>");
out.print("<td>" + rs.getDouble(17) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(18) + "</td>");
out.print("<td>" + rs.getDouble(18) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(19) + "</td>");
out.print("<td>" + rs.getDouble(19) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(20) + "</td>");
out.print("<td>" + rs.getString(20) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(21) + "</td>");
out.print("<td>" + rs.getInt(21) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(22) + "</td>");
out.print("<td>" + rs.getString(22) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(23) + "</td>");
out.print("<td>" + rs.getInt(23) + "</td></tr>");
out.print("<tr><td>" + rsmd.getColumnName(24) + "</td>");
out.print("<td>" + rs.getInt(24) + "</td></tr>");
}
out.print("</table>");
} catch (Exception e2) {
e2.printStackTrace();
}
finally {
out.close();
}
}
}
答案 0 :(得分:0)
我建议使用某种pdf生成器库,这样您就可以使用您喜欢的样式创建PDF数据。
来自Google搜索的图书馆的一个例子是PdfBox https://pdfbox.apache.org/,但您可以自由使用。
您所做的一般方法是以编程方式创建Pdf文档并将其填入您的数据。通常应该有一种方法来以您想要的格式设置Pdf样式(实现将取决于您使用的库)。
您需要将文件保存在某处(无论是在服务器上还是在云平台上),以允许用户下载pdf。然后在网页上向用户显示下载链接。