我正在用Spring做一个项目,我有这个问题,我谷歌了错误信息,我找到了解决方案,甚至所有关于这个问题的帖子
java.lang.IllegalStateException: "getOutputStream()" has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:578)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:212)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:115)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:108)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:175)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.WEB_002dINF.Pages.generate_jsp._jspService(generate_jsp.java:209)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:230)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
@RequestMapping(method = RequestMethod.GET, value = "/GenerateM")
public String genererGet(HttpServletRequest request, ModelMap model, HttpServletResponse response) throws Exception {
// Some code ...
OutputStream out;
try {
response.setContentType("rtf");
String filename = name + ".out.rtf";
response.setHeader("Content-Disposition", "attachment; filename = " + filename);
out = response.getOutputStream();
FileInputStream in = new FileInputStream(new File(rtf.getRtfOutput()));
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();
out.flush();
out.close();
} catch (IOException a) {
a.printStackTrace();
}
return "generate";
}
有人能帮忙吗?
您首先自己编写一个响应,然后返回视图的名称,从而告诉Spring它应该使用generate.jsp
生成一个HTML页面。
使您的方法返回void
而不是字符串。HTTP响应只能有一个主体:要么是文件附件,要么是HTML页面,但不能两者兼而有之。
问题内容: 我谷歌的错误消息 ,很多人说,这是因为后面的空格或换行,但在我的代码,没有一个空格或一个换行符。我在Linux上使用tomcat6。 根本原因 问题答案: 好的,你应该使用servlet而不是JSP,但是如果你确实需要…在页面顶部添加以下指令: 或者在jsp-config部分中,你的web.xml 此外flush/ close中OutputStream和返回完成时。
我正在尝试使用以下代码段在浏览器中打开pdf文件: 我收到以下错误: 我还尝试使用以下方式关闭: 有人能帮我吗?
我有一个包含表的JSP页面。加载页面时,将填充表。我还有一个每隔X秒的ajax调用,它必须刷新表内容。 加载时,按预期填充内容。但在ajax调用期间,它会失败,并出现以下错误: 我检查了这个问题上存在的问题,但没有什么好结果。我没有在代码中使用scriplets。 JSP代码: 控制器代码:
稍后,在同一个JSP中,我调用一个方法,该方法最终调用jasper-reports: HttpServletResponse对象“Response”被传递给以下方法,在调用时发生错误: 我已经查看了以下堆栈溢出帖子,仍然需要一些关于如何修复此问题的指导:
代码: 我的如下所示: 在JSP中,我只是给出了一个按钮,它给出了对话框。单击该按钮后,我将获得异常。 如何避免这一点?