I have a JSP page which contains a table. 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.
On load, the contents are populated as expected. But during ajax call, it fails with below error:
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:
$(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();
}