Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'jasperreports 3.5 for java developers- p8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 11 connection DriverManager.getConnection jdbc mysql localhost 3306 flightstats user user password secret JasperRunManager.runReportToPdfStream reportStream servletOutputStream new HashMap connection connection.close servletOutputStream.flush servletOutputStream.close return mapping.getInputForward All the action classes must extend the org.apache.struts.action.Action class. Typically the execute method is overridden to implement custom logic for servicing a request. As can be seen in this code the execute method takes an instance of HttpServletResponse as one of its parameters. This makes it easy to write action classes that generate reports. The technique illustrated in the preceding example is not much different from what we have seen in various earlier examples throughout the book. In most examples we used standard Java servlets to generate web reports implementing the report logic in the servlet s doGet method. As both the HttpServlet.doGet and Action.execute methods take an instance of HttpServletResponse as one of their parameters the technique to generate a report from an action class is virtually identical to the technique used when employing a servlet. Let us take a look at the JSP that will invoke the GenerateReportAction.execute method. @ taglib uri http struts.apache.org tags-html prefix html DOCTYPE HTML PUBLIC - W3C DTD HTML 4.01 Transitional EN html head title Generate Report title head body p Click on the button to generate the report. p html form action generate_report html submit html form body html 339 Integrating JasperReports with Other Frameworks This JSP will generate a very simple HTML form with a Submit button as its only input field. Next let us take a look at the form bean for this JSP. package net.ensode.jasperbook.struts import org.apache.struts.action.ActionForm public class GenerateReportForm extends ActionForm As the HTML form generated by the preceding JSP has no input fields other than a Submit button its corresponding .