Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring's Json not being resolved with appropriate response
    primarykey
    data
    text
    <p>I've tried to have a controller in Spring return a JSON response to no avail using the Jackson classes as <a href="http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/" rel="noreferrer">recommended with 3.0</a>. I've got the jackson jar files(jackson-core-asl-1.5.5.jar &amp; jackson-mapper-asl-1.5.5.jar) in my class path of course.</p> <p>As for the appconfig.xml entries, I'm not sure I need these. I've put them in there as a last act of desperation before returning to ol' fashion non-json ajax. </p> <p>In debug, I watch the controller get the request, return the foo and then, in firebug, get a 406.</p> <p>The error messages are as follows: From the logger when set to debug: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation</p> <p>From the response: (406) The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().</p> <p>My appconfig.xml is here:</p> <pre class="lang-xml prettyprint-override"><code> &lt;!-- Configures support for @Controllers --&gt; &lt;mvc:annotation-driven /&gt; &lt;!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory --&gt; &lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt; &lt;property name="mediaTypes"&gt; &lt;map&gt; &lt;entry key="html" value="text/html"/&gt; &lt;entry key="json" value="application/json"/&gt; &lt;/map&gt; &lt;/property&gt; &lt;property name="viewResolvers"&gt; &lt;list&gt; &lt;bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/WEB-INF/views/"/&gt; &lt;property name="suffix" value=".jsp"/&gt; &lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="defaultViews"&gt; &lt;list&gt; &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt; &lt;property name="basename" value="messages"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre> <p>My controller</p> <pre><code>@RequestMapping(value="foo/bar", method=RequestMethod.GET) public @ResponseBody foo getFoo(@RequestParam String fooId) { return new foo(fooId); } </code></pre> <p>On the jsp, where the ajax call is made:</p> <pre><code>function addRow() { $.getJSON("foo/bar",{ fooId: 1} , function(data) { alert("it worked."); }); </code></pre> <p>}</p> <p>Let me know if there's any more info that is needed. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload