• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

406 (Not acceptable) message during AJAX call to Spring Controller.

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting 406 (Not acceptable) message during AJAX call to Spring Controller.

The Spring code:




The ajax call:



thanks
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change the return type in your spring class to Object instead of product and add contentType: "application/json" to your AJAX call.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed the return type in the spring controller class to Object instead of product and added contentType: "application/json" to the AJAX call. The error message is same: http://localhost:8080/MyShoppingCart/getAjaxProductInfo.htm 406 (Not Acceptable)


Spring code:



The jquery code:


 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you try adding produces attribute to your RequestMappinglike this, @RequestMapping(value = "/getAjaxProductInfo.htm", method = RequestMethod.POST,produces="application/json").

Also, can you show us your classpath libraries..
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that and got same error message.

The classpath:

antlr-2.7.7.jar
commons-logging.jar
dom4j-1.6.1.jar
jquery-2.0.3.js
jquery-2.0.3.min.js
jquery-2.js
jstl.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.context.support-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
org.springframework.web-3.1.1.RELEASE.jar
org.springframework.web.servlet-3.1.1.RELEASE.jar
standard.jar





I also tried adding jackson-all-1.9.0.jar to the classpath.


I got some response when using a GET request and sending a string "hello" in request from the browser. I do not need a single string like hello to be displayed in my HTML but need some properties of Product like product.price, product.type etc. But when sending Product as response there is error message :

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()




My Spring controller code:




So the issue is I am able to send Hello a single string in the response using below url

http://localhost:8080/MyShoppingCart/getAjaxResponse.htm?productId=abc

but I need more information to be displayed in HTML like product.price, product.type.

thanks

 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to register the MappingJacksonHttpMessageConverter as below and add <mvc:annotation-driven/> to your spring configuration file.

 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to get AJAX response onto the JSP page as below. However this way I am only able to pass the product.getPrice() as the AJAX response whereas I want to pass product.getType() also along with product.getPrice().





and the Spring controller code:






This works fine. However this way I am only able to pass the product.getPrice() as the AJAX response whereas I want to pass product.getType() also along with product.getPrice(). How can this be done ?

thanks
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try adding MappingJacksonHttpMessageConverter as i wrote earlier?
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. I am trying that and am reading about Jackson and why its is required, What it does.
 
reply
    Bookmark Topic Watch Topic
  • New Topic