我得到406不能接受并且耗尽我所有的时间。我尝试了很多,但请不要解决,请帮助我。
AJAX
$('#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;
}
配置xml
<?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>
现在我在ajax请求上收到此错误。我可以在这样的XHR响应中看到。
HTTP状态406 - 此请求标识的资源仅为 能够产生具有不可接受特征的响应 根据请求“接受”标题()。
标题
**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
jackson-mapper,jackson-core,jackson jaxrs也加入了项目。 有人请帮助我,我在stackoverflow中看到类似的问题,解决方案降级到春季3.1,是真的。我现在正在使用3.2 ..
谢谢和问候