我使用ajax发布数据:
<script>
$(document).ready(function(){
$("#l").click(function(){
if($("#number").val().length <= 5 || $("#password").val().length <= 5){
$("#show").show();
} else {
$("#show").hide();
$.ajax({
url:"index/judement",
type:"POST",
dataType:"json",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify({
number:$("#number").val(),
password:$("#password").val()
}),
success: function (data) {
var a = data.message;
if(a=="true"){
alert(data.message);
} else {
$("#show").show();
}
},
error: function () {
alert("error");
}
});}
});
})
</script>
但它为我返回 415 代码!所以我早上搜索了很多方法。最后,我将这段代码添加到我的mvc-dispatcher-servlet.xml
:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
它工作!但是当我关闭 IDE 并重新启动时,它会出错!!!天哪!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'jsonHttpMessageConverter' while setting bean property 'messageConverters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonHttpMessageConverter': Failed to introspect bean class [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultPrettyPrinter$Indenter
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonHttpMessageConverter': Failed to introspect bean class [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultPrettyPrinter$Indenter
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultPrettyPrinter$Indenter
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.util.DefaultPrettyPrinter$Indenter
现在,什么鬼?