Straight into the topic-
Page form Asynchronous commit: $.post (' <%=request.getcontextpath ()%>/web/register.html ', $ (form). Serialize (), function (data) {... });
The controller of the Java backend SPRINGMVC accepts the request:
@RequestMapping ("register")
@ResponseBody
Public map<string, string> Register (httpservletrequest request, httpservletresponse response, user user) {
map<string, string> resmap = loginservice.insertuser (user);
return resmap;
}
Error description, the SPRINGMVC controller receives the AJAX request sent by the page, and the Java background processing times is wrong:
[DEBUG] [2016-02-14 20:08:09] Org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException ( 133) | Resolving exception from handler [[email protected]]:Org.springframework.web.HttpMediaTypeNotAcceptableException:Could not find acceptable representation
[DEBUG] [2016-02-14 20:08:09] Org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException ( 133) | Resolving exception from handler [[email protected]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
[DEBUG] [2016-02-14 20:08:09] Org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException ( 133) | Resolving exception from handler [[email protected]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
[DEBUG] [2016-02-14 20:08:09] Org.springframework.web.servlet.DispatcherServlet.processDispatchResult (1034) |Null Modelandview returned to Dispatcherservlet with Name ' rest ': Assuming Handleradapter completed request handling
[DEBUG] [2016-02-14 20:08:09] org.springframework.web.servlet.FrameworkServlet.processRequest (999) | Successfully completed request
[DEBUG] [2016-02-14 20:08:09] Org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (251) | Returning cached instance of singleton Bean ' sqlsessionfactory '
At this point the corresponding page error is:
POST http://127.0.0.1:8080/maven-web-demo/web/register.html 406 (not acceptable)
Cause: Missing JSON configuration for SPRING-MVC
Workaround:
1. Add Spring-mvc JSON dependency jar package: Jackson-core and Jackson-databind
2. Add in Spring-mvc.xml:
<bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name= "Messageconverters" >
<list>
<ref bean= "Mappingjacksonhttpmessageconverter"/>
</list>
</property>
</bean>
<bean id= "Mappingjacksonhttpmessageconverter" class= " Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter ">
<property name= "Supportedmediatypes" >
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
OK, problem solved!
SPRINGMVC 406 error in resolving AJAX requests