Я работаю над веб-приложением, основанным на загрузке Spring, и использую Thymeleaf на внешней стороне.У меня есть требование совершить AJAX-вызов, POST-данные и данные об успешном отображении, полученные из AJAX-вызова.
ниже приведен AJAX-вызов для вызова метода Controller
var myObject = new Object();
myObject.acctTypeValue = 22;
myObject.amtBalance = "121334";
myObject.custNo="12121";
myObject.userId="2345rest";
$.ajax({
url : '/testDocWeb/forwardToCallingSystem',
type :'POST',
data : myObject,
dataType:'html',
cache: false,
timeout: 600000,
success : function(data) {
alert('Data: '+JSON.stringify(data));
},
error : function(request,error)
{
alert("Error : "+JSON.stringify(request));
}
});
и ниже контроллер Spring MVC: -
@PostMapping(path="/forwardToCallingSystem")
public @ResponseBody DummuyResponse forwardToCallingSystem(@ModelAttribute DummyInput dummyInput,Model model, HttpServletRequest request) {
log.info("Inside forwardToCallingSystem method." );
DummuyResponse dummyResponse = new DummuyResponse ();
dummyResponse .setDocId("756");
dummyResponse .setReasonCode('0');
dummyResponse .setReturnCode(100);
dummyResponse .setStatusCode(200);
return dummyResponse ;
}
и ниже объект Model, который я возвращаю: -
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class DummyResponse implements Serializable {
private static final long serialVersionUID = -8191562770215698813L;
private int statusCode;
private char reasonCode;
private int returnCode;
private String docId;
}
Я не уверенчто не так, но я получаю ниже ошибку при выполнении этого вызова AJAX: -
[ERROR]~2019-06-12-10.32.54.030CDT~~~~~~ o.a.c.c.C.[.[localhost] Exception Processing ErrorPage[errorCode=0, location=/error]
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:580)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:516)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:388)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:348)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:173)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at net.rakugakibox.spring.boot.logback.access.tomcat.LogbackAccessTomcatValve.invoke(LogbackAccessTomcatValve.java:91)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response
У меня проблема только при создании веб-страницы формы вызова AJAX Thymeleaf для нормальной Spring MVC, она работает нормально. Любая помощь будетцениться