在Jasper Report Web Application的JSP中,PDF无法相应地呈现

时间:2018-10-10 09:46:16

标签: jsp jasper-reports

我刚刚在JSP中为Jasper iReport制作了一个Web应用程序。来自iReport应用程序的报告显示完全没有问题。但是有些报告没有在JSP中显示。看来JSP的pdf无法正确呈现。有什么办法解决此问题吗? 我使用Here

中的apache-tomcat-7.0.91和jasperreports-5.1.2库

JSP代码:

<%@ page language="java" contentType="application/pdf; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.text.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="net.sf.jasperreports.engine.*" %>

        <%
            Connection con;
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/report", "root", "H@zel2002");
            File rf= new File(application.getRealPath("ireport/A2.jasper"));

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String dateString = format.format( new Date()   );
            Date date = format.parse ( request.getParameter("trip") ); 
            HashMap parameters = new HashMap();
            parameters.put("startdate",date);

            byte[] bytes= JasperRunManager.runReportToPdf(rf.getPath(),parameters,con);
            //response.setContentType("application/pdf");
            response.setContentLength(bytes.length);
            ServletOutputStream outStream = response.getOutputStream();
            outStream.write(bytes, 0, bytes.length);
            outStream.flush();
            outStream.close(); 
        %>

PDF from JSP

Result from iReport

0 个答案:

没有答案