我有一个包含表格的JSP页面。在加载页面时,将填充表格。我每隔X秒也有一次ajax调用,必须刷新表内容。
在加载时,将按预期填充内容。但是在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)
我检查了这个问题的现有问题,但没有好处。我在代码中没有使用scriplets。
JSP COde:
$(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);
});
控制器代码:
@RequestMapping(value = "/refresh")
public @ResponseBody
RefresingModel refresh(ModelMap modelMap,
HttpSession session) {
return refreshService.getUpdatedData();
}
答案 0 :(得分:0)
不要在JQuery中使用out
对象。它是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);
});