各位大侠,救命!getOutputStream() has already

不断的重复 发布于 2012/09/27 13:16
阅读 8K+
收藏 0

解读下一代网络:算力网络正从理想照进现实!>>>

spring mvc 3.1  jackson 1.9
ajax请求
this.getNew = function(code) {
gps.track = true;
$.ajax({
url: "/gpsdata/get", 
type: "post",
data: {"code": ''}, 
success: function(datas) {
if (datas) {
var json = null;
var arrayl = [];
for (var i in datas) {
json = datas[i];
if (!json) break;
json.icon = "gps_off.png";
arrayl.push(json);
}
if (arrayl.length>0) {
var effect = NtGis.api.markLayer.effect;
var tmpeffect = effect;
NtGis.api.markLayer.effect = false;
NtGis.api.addMarkers(arrayl, 24, 35, new gps.newPoint(), true, true, true, gps.markerClickCallBack,true);
NtGis.api.markLayer.effect = tmpeffect;
}
}
if (gps.track) {
setTimeout(function(){gps.getNew();},6000);
}
},
error: function() {
if (gps.track) {
setTimeout(function(){gps.getNew();},6000);
}
}});
}
返回数据:(最高峰时返回30个这样的JSON对象)
{"dwt64":{"id":"8ad599743a062046013a06205e780000","name":null,"code":"dwt64","lonlat":"POINT(111.93962721969218 25.590559142889546)"}}
一个小时左右报错,

<html><head><title>Apache Tomcat/7.0.30 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - java.lang.IllegalStateException: getOutputStream() has already been called for this response</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>java.lang.IllegalStateException: getOutputStream() has already been called for this response</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>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.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
</pre></p><p><b>root cause</b> <pre>java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:639)
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.layout.platform.error_jsp._jspService(error_jsp.java:76)
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.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.30</h3></body></html>
加载中
0
panmingguang
panmingguang
我也发现这个问题,  检查使用  res. getOutputStream()  使用过后 流没有关闭 , 关闭后就正常了
0
panmingguang
panmingguang
不好意思,说错, 以上无法解决, 同时使用outputstream 和writer 关闭了也不行
0
RogerZhu
RogerZhu

以前在网上找到的解决方法:

out.clear();

out = pageContext.pushBody();

RogerZhu
RogerZhu
回复 @energy : 我以前出现这个错误是使用OutputStream输出了一张图片,然后再使用out.write()输出其他内容时出现的,这段就是加在关掉OutputStream后面的。
不断的重复
不断的重复
这段代码在那加?
0
不断的重复
不断的重复

像这类答案已经在网上找过很多,不能解决

是关tomcat问题还是程序问题?

0
RogerZhu
RogerZhu

引用来自“energy”的答案

像这类答案已经在网上找过很多,不能解决

是关tomcat问题还是程序问题?

看过一些解释,jsp默认对象out实际调用的是response.getWriter(),而JSP不允许同时使用response.getWriter()和response.getOutoutStream(),错误就是这么出现的,在页面上加out.clear();out = pageContext.pushBody();可以解决,具体原理也不是太懂。

还有种情况是说在一些版本的tomcat上<%%>前后的空格和空行会导致这个错误。

这个地址你可以看一下:

http://stackoverflow.com/questions/1776142/getoutputstream-has-already-been-called-for-this-response

0
不断的重复
不断的重复
我返回的是json,没有页面,应该怎样加?
返回顶部
顶部