gpt4 book ai didi

java - 如何在客户端jsp上显示报表?

转载 作者:行者123 更新时间:2023-12-01 12:31:09 24 4
gpt4 key购买 nike

我正在尝试在jsp页面中显示结果。在我的 Index.html 中有一个链接, <a href="vehicleReport.jsp">Vehicle Report</a>

vehicleReport.jsp我将报告显示为,

<body>
<%
Connection con=null;
try{
con=VehicleDetails.getConnection();
InputStream inputStream = new FileInputStream ("E:/ReportFld/report4.jrxml");

Map parameters = new HashMap();

JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
@SuppressWarnings("unchecked")
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
out.clear(); // where out is a JspWriter
out = pageContext.pushBody();
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
}
catch(Exception e){e.printStackTrace();}
finally{
con.close();
}

%>
</body>

但问题是报告不可见。在jsp中它显示一些不可读的文本。我收到错误消息,

SEVERE: Servlet.service() for servlet [jsp] in context with path [/Reports] threw exception [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:636)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)

如何解决这个问题?

最佳答案

尝试使用

JasperExportManager.exportReportToPdfFile(JasperPrint jsperPring, String fileName);

而不是

JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

然后在浏览器或任何您想要的地方显示您的 pdf。

关于java - 如何在客户端jsp上显示报表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25908004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com