I am building a web app in spring MVC.
I want to retrieve List of patient (collection) using Ajax. But it throws me error of 406 not acceptable
Jsp File
$(document).ready(function () {
$.ajax({
url: 'searchPatient',
//data: "uhid=" + $("#uhid").val() + "&type=" + $("#type").val(),
contentType: 'application/json',
dataType: 'json',
success: function (data) {
alert(data);
}
});
});
** Controller File
@RequestMapping("/searchPatient")
public @ResponseBody List<String> getPatient()
{
List<String> s = new ArrayList<String>();
s.add("hello");
return s;
}
How can I solve this error?
您的请求URI为http://…/ HMIS / searchPatient,因此请确保将DispatcherServlet映射到/ HMIS / *或它已存在于控制器@RequestMapping中
I know this is an old question, but I also had this error an solved it adding the definition for MappingJacksonHttpMessageConverter like this:
<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>
Link to the original answer hope it helps someone else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.