使用 PrintWriter 和 OutputStream

发布于 2024-08-17 14:21:31 字数 1349 浏览 3 评论 0原文

我正在使用 struts 创建一个项目,但在使用 Jasper IReports 时遇到问题。我想将一些信息导出到 pdf 文件中,但我不断收到 java.lang.IllegalStateException: getOutputStream() 已被调用...由于当页面已打开 PrintWriter 时在我的代码中打开 ServletOutputStream 而出现异常。

代码位于模型中(因此它不在 jsp 中,而是在 java 文件中),如下所示:

    public void handle(HttpServletResponse res, Connection connection, String path)throws Exception{
    ServletOutputStream out = null;
    try {

        JasperDesign jasperDesign = JRXmlLoader.load(path);
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        byte[] bytes = JasperRunManager.runReportToPdf(jasperReport, null, connection);
        res.setContentType("application/pdf");
        res.setContentLength(bytes.length);
        out = res.getOutputStream();
        out.write(bytes, 0, bytes.length);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.flush();
        out.close();
    }

我已经检查了连接、路径和 HttpServletResponse,并且都工作正常。

我是 Jasper Reports 以及将内容编码为 PDF 的新手,所以你可以正确地假设我对我在这里所做的事情有一个最低限度的了解,显然我的代码是通过网络从某个地方复制/粘贴的。

我尝试使用 PrintWriter 而不是 OutputStream,将字节转换为字符串并使用 PrintWriter.append(String) 方法(allthought 不是 String 是 CharSequence),但它不会将数据提取到 PDF 中。

我还尝试获取 PrintWriter,关闭它以打开 OutputStream (不起作用)或刷新它(两者都不是)。

任何有关使用任何可以在 pdf 中显示数据的输出的解决方案的帮助都会很棒。 多谢!

I am creating a project with struts and I have a problem using Jasper IReports. I want to export some info into a pdf file and I keep getting the java.lang.IllegalStateException: getOutputStream() has already been call... Exception due to openning a ServletOutputStream in my code when the page already opens a PrintWriter.

The code is in the model (so it is not in the jsp, it's in a java file), as it follows:

    public void handle(HttpServletResponse res, Connection connection, String path)throws Exception{
    ServletOutputStream out = null;
    try {

        JasperDesign jasperDesign = JRXmlLoader.load(path);
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        byte[] bytes = JasperRunManager.runReportToPdf(jasperReport, null, connection);
        res.setContentType("application/pdf");
        res.setContentLength(bytes.length);
        out = res.getOutputStream();
        out.write(bytes, 0, bytes.length);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.flush();
        out.close();
    }

I have checked the connection, the path and the HttpServletResponse and are all working fine.

I'm very newbie with Jasper Reports as well as with coding stuff into PDF so you can -correctly- suposse that I have a minimal idea of what I am doing here and that, obviously my code is copy/pasted from somewhere through the net.

I have tried to use PrintWriter instead of OutputStream, transforming bytes into a String and using the PrintWriter.append(String) method (allthought is not String is CharSequence), but it doesn't extract the data into the PDF.

I have also tried to get the PrintWriter, close it to open the OutputStream (didn't work) or flush it (neither).

Any help with a solution to use any out that could show the data in a pdf would be great.
Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

安静 2024-08-24 14:21:31

查看堆栈跟踪很有用。

不过,您可以先尝试运行完整性检查:修改该代码以简单地将静态字符串 (hello world) 写入 ServletOutputStream 并将内容类型设置为 text/html。因为这应该可以正常工作:

public void handle(HttpServletResponse res, Connection connection, String path)throws Exception{
ServletOutputStream out = null;
try {
    byte[] bytes = "hello world".getBytes();
    res.setContentType("text/html");
    res.setContentLength(bytes.length);
    out = res.getOutputStream();
    out.write(bytes, 0, bytes.length);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    out.flush();
    out.close();
}

HTH

Would be useful to see the stack trace.

You might try running a sanity check first though: Modify that code to simply write a static string (hello world) to the ServletOutputStream and set content type to text/html. As that should work fine:

public void handle(HttpServletResponse res, Connection connection, String path)throws Exception{
ServletOutputStream out = null;
try {
    byte[] bytes = "hello world".getBytes();
    res.setContentType("text/html");
    res.setContentLength(bytes.length);
    out = res.getOutputStream();
    out.write(bytes, 0, bytes.length);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    out.flush();
    out.close();
}

HTH

删除会话 2024-08-24 14:21:31

一些想法:

  • 如果您使用二进制流(PDF 是二进制的),PrintWriter 将无法工作
  • 如果客户端超时或断开连接,则可能会出现非法状态。该过程的数据包跟踪会告诉您很多信息(即使您不能很好地阅读它们)。查看 WireShark 或适用于您的平台的内容。值得您花时间至少了解一点有关线路级别发生的事情。
  • 确保您从报告生成中返回的数据实际上是 pdf 文件。将其写入文件并尝试打开。
  • 有些情况需要您在写入流之前设置 http 长度标头,否则当数据开始显示时它们会放弃。这里可能有必要。

Some ideas:

  • PrintWriter isn't going to work if you are working with a binary stream (PDF are binary)
  • The illegal state might occur if there is client side timeout or disconnect. A packet trace of the process will tell you a lot (even if you can't read them well). Look at WireShark or what is available for your platform. Its worth your time to learn at least a little bit about what happens at the wire level.
  • Make sure the data you are getting back from the report generate is actually a pdf. Write it to a file and attempt to open.
  • Some situations need you to set the http length header before writing to the stream otherwise they give up when the data starts to show. Might be necessary here.
心作怪 2024-08-24 14:21:31

代码具体是如何调用的呢?从堆栈跟踪来看,您似乎正在使用 JSP 文件(inicio2.jspscriptlet 来通过 handle 方法运行 Java 类> 准确地说)。在 Java 类将报告写入 OutputStream 后,JSP 文件将继续输出文件本身的剩余部分(包括空格!),这将隐式调用 getWriter() 将其写入响应。确切地说,当之前在 Java 类中调用了 getOutputStream() 时,这会导致您现在所面临的 IllegalStateException 异常。

将 Java 代码放在 Java 类中固然很好,但这并不意味着您仍然可以使用 JSP 来调用它。 JSP 不应包含任何一行 Java 代码。 JSP 本身就是作为视图技术输出的一部分。要解决这一切,只需拥有一个 Struts 操作类(或 HttpServlet),您可以通过 HTML

< 调用它/代码>。

How exactly is the code invoked? Judging from the stacktrace it look like that you're running the Java class with the handle method using scriptlets inside a JSP file (the inicio2.jsp to be precise). After that the Java class has written the report to the OutputStream, the JSP file would continue with outputting the remnant of the file itself (including whitespace!), which would implicitly invoke the getWriter() to write it to response. Exactly that would cause an IllegalStateException as you're facing now when the getOutputStream() is already been called before in the Java class.

It's good that Java code is been placed in a Java class, but that doesn't mean that you may still use JSP to invoke it. The JSP should not contain any single line of Java code. JSP itself is as being a view technology part of the output. To fix this all, just have a Struts action class (or a HttpServlet) which you can invoke by a HTML <form> or <a>.

请持续率性 2024-08-24 14:21:31

自己的答案:

我在路径中放入了一个jrxml,它实际上连接到数据库并获取一些真实数据,突然它工作了,PDF在mozilla中打开,但异常不断发生。我不知道如何抛出异常(我已经调试并且异常发生在同一个地方)并能够看到 PDF。

所以我只能继续寻找这里究竟发生了什么。我会回答我发现的任何问题(可能在周一)。

感谢 simonlord 和 Jim Rush 的帮助! :)

编辑:顺便说一句,这是堆栈跟踪(它是西班牙语,如果需要,我会翻译您不明白的任何内容):
再次编辑:似乎我没有复制 2010 年 1 月 15 日的“1”...可能会对 1 月 5 日 insetad 的跟踪造成混淆。已更正。

15-ene-2010 13:47:03 org.apache.catalina.core.ApplicationDispatcher invoke
GRAVE: El Servlet.service() para servlet jsp lanzó una excepción
java.lang.IllegalStateException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.catalina.connector.Response.getWriter(Response.java:607)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:171)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)
    at org.apache.jsp.pages.inicio2_jsp._jspService(inicio2_jsp.java:300)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.struts.chain.commands.AbstractExceptionHandler execute
ADVERTENCIA: Unhandled exception
org.apache.jasper.JasperException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.struts.chain.commands.ExceptionCatcher postprocess
ADVERTENCIA: Exception from exceptionCommand 'servlet-exception'
org.apache.jasper.JasperException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet action lanzó excepción
java.lang.IllegalStateException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.catalina.connector.Response.getWriter(Response.java:607)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:171)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)
    at org.apache.jsp.pages.inicio2_jsp._jspService(inicio2_jsp.java:300)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

Own answer:

I have put in the path a jrxml that actually connects to the database and gets some real data out and suddendly it worked, the PDF opened in mozilla, but the Exception keeps happening. I do not know how I can throw and exception (I have debugged and the Exception happens in the same place) and be able to see the PDF.

So I can only keep searching for what actually happens here. I will answer with anything I find (probably on monday).

Thanks simonlord and Jim Rush for your help! :)

Edit: By the way, here is the stacktrace (it's in Spanish, if needed I will translate anything you don't understand):
Edit again: Seems I didn't copy the '1' in the 15th-Jan-2010... could create confusion about a trace from the 5th-Jan insetad. Corrected.

15-ene-2010 13:47:03 org.apache.catalina.core.ApplicationDispatcher invoke
GRAVE: El Servlet.service() para servlet jsp lanzó una excepción
java.lang.IllegalStateException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.catalina.connector.Response.getWriter(Response.java:607)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:171)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)
    at org.apache.jsp.pages.inicio2_jsp._jspService(inicio2_jsp.java:300)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.struts.chain.commands.AbstractExceptionHandler execute
ADVERTENCIA: Unhandled exception
org.apache.jasper.JasperException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.struts.chain.commands.ExceptionCatcher postprocess
ADVERTENCIA: Exception from exceptionCommand 'servlet-exception'
org.apache.jasper.JasperException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
15-ene-2010 13:47:03 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet action lanzó excepción
java.lang.IllegalStateException: getOutputStream() ya ha sido llamado para esta respuesta
    at org.apache.catalina.connector.Response.getWriter(Response.java:607)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:171)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)
    at org.apache.jsp.pages.inicio2_jsp._jspService(inicio2_jsp.java:300)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:141)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:92)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文