Spring 406不接受来自ajax的请求
我得到了406分,这是不可接受的,我的时间都在消耗。我试了很多,但是没有解决,请帮帮我 ajaxSpring 406不接受来自ajax的请求,spring,jquery,spring-mvc,jackson,Spring,Jquery,Spring Mvc,Jackson,我得到了406分,这是不可接受的,我的时间都在消耗。我试了很多,但是没有解决,请帮帮我 ajax $('#cls').autocomplete({ source: function(request, response) { $.ajax({ url: "classes.htm", data: {}, contentT
$('#cls').autocomplete({
source: function(request, response) {
$.ajax({
url: "classes.htm",
data: {},
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
response(data.names)
}
,
error:function(jqXHR, textStatus, errorThrown){
alert(textStatus);
}
})
}
});
弹簧控制器
@RequestMapping(value="/classes.htm", method = RequestMethod.GET, headers="Accept=*/*")
public @ResponseBody List<String> getClasses() {
System.out.println("ajax");
List<Classes> classes = homeService.getClasses();
List<String> clsNames = new ArrayList<String>();
for(Classes cls: classes)
{
clsNames.add(cls.getName());
}
return clsNames;
}
项目中还添加了jackson mapper、jackson core和jackson JAXR。
有人请帮助我,我在stackoverflow中看到了类似的问题,解决方案是降级到Spring3.1,这是真的吗。我现在正在使用3.2
感谢和问候使用相同的配置,我降级到spring 3.1,这很有效。为什么不在3.2版本中?您是否尝试过更改jackson的版本?您是否尝试过直接从浏览器而不是通过PHP访问端点?如果是这样的话,你也会犯同样的错误吗?我刚刚用Spring3.2解决了这个问题,看起来你做的一切都是正确的。唯一的区别是我使用的是Jackson 2.x,而不是1.x
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd>
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:annotation-config />
<context:component-scan base-package="org.app.bluez." />
<mvc:annotation-driven />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:resources/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jndiName"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:resources/hibernate.cfg.xml</value>
</property>
<property name="packagesToScan" value="org.app.bluez.domain" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
</beans>
**Response Headers**
Content-Length 1070
Content-Type text/html;charset=utf-8
Date Sat, 11 May 2013 21:59:55 GMT
Server Apache-Coyote/1.1
**Request Headers**
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Content-Type application/json; charset=utf-8
Cookie JSESSIONID=DDAC77BE351C26015C6494685E7AC225
DNT 1
Host localhost:8084
Referer http://localhost:8084/Bluez/register.htm
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0
X-Requested-With XMLHttpRequest