Reputation: 2488
I am getting HttpMediaTypeNotAcceptableException
when making a jQuery ajax call.
I have the following configuration.
In context I have (this is in classpath)
<context:component-scan base-package=" group package" />
<mvc:annotation-driven />
and I have in servlet-config
<context:component-scan base-package="controller pacakges alone" />
<mvc:annotation-driven />
I have added jackson-mapper-asl 1.9.13
in the pom.xml and using spring core 3.2.4
and security 3.1.4
I have a jQuery ajax call
$.ajax({
url : "checkUser.html",
cache : false,
type : "post",
data : "email=" + $('#email').val(),
success : function(response) {
success callback;
}
});
I'm getting this exception:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
Upvotes: 0
Views: 846
Reputation: 503
This is a better explanation : http://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc
You might want to set acceptable mediaTypes like :
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
</property>
Further you could simply send parameters like
var url = "/checkUser/" + $('#email').val() + ".htm";
$.ajax({
type: "POST",
url: url,
success: function(msg){
in the Controller
@RequestMapping(value = "/checkUser/{email}",method = RequestMethod.POST)
Upvotes: 2
Reputation: 2488
alas i got it , the spring 3.2 version made below change to Configuring Content Negotiation caused the issue ,since content negotiation done by through file extensions by default , my pages stopped working upon upgrading to 3.2 version.
i have disable above file media type extension
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
<property name="favorParameter" value="true" />
<property name="mediaTypes">
<value>
json=application/json
xml=application/xml
</value>
</property>
</bean>
this post for more info.
HttpMediaTypeNotAcceptableException after upgrading to Spring 3.2
Upvotes: 0