[英]IllegalStateException: getOutputStream() has already been called for this response
I have a JSP page which contains a table.我有一个包含表格的 JSP 页面。 On load of the page, the table will be populated.在页面加载时,表格将被填充。 I also have an ajax call for every X seconds which has to refresh the table contents.我也每 X 秒有一个 ajax 调用,它必须刷新表内容。
On load, the contents are populated as expected.加载时,内容按预期填充。 But during ajax call, it fails with below error:但是在ajax调用期间,它失败并出现以下错误:
Jul 31, 2014 3:17:16 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [SpringDispatcherServlet] in context with path [/sample] threw exception [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:638)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:105)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:105)
at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.getWriter(SaveContextOnUpdateOrErrorResponseWrapper.java:109)
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:190)
I checked the existing questions on this issue, but with no good.我检查了有关此问题的现有问题,但没有任何好处。 I am not using scriplets in the code.我没有在代码中使用脚本。
JSP COde: JSP代码:
$(document)
.ready(
function() {
var performAjax = function() {
$
.ajax({
method : 'get',
contentType: 'application/json',
dataType: "json",
url : "${pageContext.request.contextPath}/refresh",
success : function(data) {
alert("got something");
},
error : function(e) {
alert('Error: ' + e);
}
});
}
setInterval(performAjax, 15000);
});
Controller code:控制器代码:
@RequestMapping(value = "/refresh")
public @ResponseBody
RefresingModel refresh(ModelMap modelMap,
HttpSession session) {
return refreshService.getUpdatedData();
}
Don't use out
object in JQuery. 不要在JQuery中out
对象。 It is a implicit object in JSP for OutputStream: 它是JSP中OutputStream的隐式对象:
$(document)
.ready(
function() {
var performAjax = function() {
$
.ajax({
method : 'get',
contentType: 'application/json',
dataType: "json",
url : "${pageContext.request.contextPath}/refresh",
success : function(data) {
alert("got something");
},
error : function(e) {
alert('Error: ' + e);
}
});
}
setInterval(performAjax, 15000);
});
The same exception is thrown when the data returned has a recursive relationship: eg Object A has collection Of Object B and and Object B has property of Type A.当返回的数据具有递归关系时,也会抛出相同的异常:例如,对象 A 具有对象 B 的集合并且对象 B 具有类型 A 的属性。
A: {
id:23,
Collection: [
B:{
id:21,
parent: A
}
]
}
Soln: add jsonIgnore on property inside Object B Soln:在对象 B 内的属性上添加 jsonIgnore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.