Java 406在春季mvc中不可接受
我正在SpringMVC中构建一个web应用程序 我想使用Ajax检索患者(集合)列表。但它给我带来了406的错误,这是不可接受的 Jsp文件Java 406在春季mvc中不可接受,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在SpringMVC中构建一个web应用程序 我想使用Ajax检索患者(集合)列表。但它给我带来了406的错误,这是不可接受的 Jsp文件 $(document).ready(function () { $.ajax({ url: 'searchPatient', //data: "uhid=" + $("#uhid").val() + "&type
$(document).ready(function () {
$.ajax({
url: 'searchPatient',
//data: "uhid=" + $("#uhid").val() + "&type=" + $("#type").val(),
contentType: 'application/json',
dataType: 'json',
success: function (data) {
alert(data);
}
});
});
**
控制器文件
@RequestMapping("/searchPatient")
public @ResponseBody List<String> getPatient()
{
List<String> s = new ArrayList<String>();
s.add("hello");
return s;
}
@RequestMapping(“/searchPatient”)
public@ResponseBody List getPatient()
{
列表s=新的ArrayList();
s、 加上(“你好”);
返回s;
}
如何解决此错误?您的请求URI是http://…/HMIS/searchPatient,因此请确保您的DispatcherServlet映射到/HMIS/*或它存在于您的控制器@RequestMapping您的请求URI是http://…/HMIS/searchPatient,因此,请确保DispatcherServlet映射到/HMIS/*或者它存在于控制器@RequestMapping中。我知道这是一个老问题,但我也解决了这个错误,添加了MappingJacksonHttpMessageConverter的定义,如下所示:
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- Bind the return value of the Rest service to the ResponseBody. -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="jsonHttpMessageConverter" />
</util:list>
</property>
</bean>
希望它能帮助其他人。我知道这是一个老问题,但我也遇到了这个错误并解决了它添加了MappingJacksonHttpMessageConverter的定义,如下所示:
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- Bind the return value of the Rest service to the ResponseBody. -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="jsonHttpMessageConverter" />
</util:list>
</property>
</bean>
希望它能帮助其他人。查看helpstry是否删除
contentType
,因为您没有向服务器发送任何数据,并且此服务器拒绝了请求。另外,GET请求不应具有请求正文。它将被大多数应用服务器拒绝。请参阅,我已将其更改为Post请求,但仍不起作用请参阅helpstry是否删除contentType
,因为您没有向服务器发送任何数据,并且此服务器拒绝该请求。另外,GET请求不应具有请求正文。它将被大多数应用服务器拒绝。请参阅,我已将其更改为Post请求,但仍不起作用