type Exception report
message org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
root cause
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Ref.RefReportCntrl_jsp._jspService(RefReportCntrl_jsp.java:630)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:640)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:126)
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)
org.apache.jsp.Ref.refverify_005ferr_jsp._jspService(refverify_005ferr_jsp.java:124)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Ref.RefReportCntrl_jsp._jspService(RefReportCntrl_jsp.java:630)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*,org.apache.log4j.Logger" %>
<%@ page isErrorPage="false" errorPage="refverify_err.jsp" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page session="true" %>
<jsp:useBean id="da" class="reports.DemographicAge"/>
稍后,在同一个JSP中,我调用一个方法,该方法最终调用jasper-reports:
if(sectionA.equalsIgnoreCase("Demographics - Age")) {
result = da.convertDtosToXml(host, parameters, response, pathToweb);
}
HttpServletResponse对象“Response”被传递给以下方法,在调用JasperExportManager.exportReportTopDfStream()
时发生错误:
package reports;
import dao.DemographicsAgeDao;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
public class DemographicAge {
private String generateDemographicAgeReport(ResultDataSource ds, Map parameters,
HttpServletResponse response, String host,
String path) throws RefugeeException {
String relativePath = path + "/Demographics_Age.xml";
String logo_path = path + "/logo.jpg";
File fin = new File(relativePath);
JasperReport jasperReport = null;
JasperDesign jasperDesign;
try {
jasperDesign = JRXmlLoader.load(fin);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
} catch (JRException e) {
e.printStackTrace();
}
parameters.put("Report Title", "Health Assessment Report");
parameters.put("Sub Title", "Reported by " + (String) parameters.get("colname"));
parameters.put("logo", logo_path);
JasperPrint jasperPrint = null;
try {
//Fill the JasperPrint object with the report data
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
//Create a unique filename using date/time
String date1 = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
String fileName = "attachment; filename=\"DemographicsAgeReport_" + date1 + ".pdf\"";
//Set the HTTP response header information
response.setHeader("Content-disposition", fileName);
response.setContentType("application/pdf");
try {
ServletOutputStream stream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, stream);
stream.flush();
stream.close();
} catch (IOException e) {
throw new RefugeeException("IO Exception while writing the content into PDF.", e.getMessage());
}
} catch (JRException e) {
throw new RefugeeException("Jasper exception while filling the report", e.getMessage());
}
return "success";
}
}
我已经查看了以下堆栈溢出帖子,仍然需要一些关于如何修复此问题的指导:
Tomcat发布的错误是一个诽谤。我的代码有一个try/catch块,用于异常,其中包括对自定义错误jsp页面(refreportcntrl_jsp.java)的调用。当refreportcntrl_jsp.java试图将字符数据推送到响应流(当前作为位流打开)时,它导致了第二个错误,这是错误日志中记录的错误。
通过查看在抛出第二个异常之前由refreportcntrl_jsp.java显示的异常字符串,可以发现真正的错误。
真正的错误在于,该项目使用的是较旧版本的Jasper和较新版本的iText。当Jasper在iText中调用一个不再作为该名称exisited的方法时,它抛出了一个方法未找到异常。
代码: 我的如下所示: 在JSP中,我只是给出了一个按钮,它给出了对话框。单击该按钮后,我将获得异常。 如何避免这一点?
我正在做关于CXF和Spring的培训,所以我写了一个非常简单的CXF演示,其中只有接口“HelloWorld”和它的实现者“HelloWorldWs”。 我想用Tomcat发布它。我编写了web.xml和applicationcontext.xml(Spring配置文件。虽然我可以发布WSDL。但是控制台列出了一个问题: 我没有使用或编写任何io函数,只是一个“sayhi”函数。我被难倒了。
最大的问题是,对于以下异常,代码片段可以正常工作。用户可以将文档保存在所需的位置。我想弄清楚为什么我会得到这个错误。
我有一个包含表的JSP页面。加载页面时,将填充表。我还有一个每隔X秒的ajax调用,它必须刷新表内容。 加载时,按预期填充内容。但在ajax调用期间,它会失败,并出现以下错误: 我检查了这个问题上存在的问题,但没有什么好结果。我没有在代码中使用scriplets。 JSP代码: 控制器代码: