Using PrintWriter and OutputStream

前端 未结 4 1597
不思量自难忘°
不思量自难忘° 2021-01-13 08:33

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.IllegalStateExcep

4条回答
  •  时光说笑
    2021-01-13 08:38

    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

    or .

提交回复
热议问题