2

I have a similar issue as given here . But i cannot solve it with the solutions provided there.

My spring application xml has only mvc annotation driven element.

<mvc:annotation-driven />

The controller code is as given.

@RequestMapping(value = "/search", method = RequestMethod.GET)
public @ResponseBody
Book performSearch(@RequestParam("CHARS") String title) {
return (Book) library.getBook(title);
}

In my javascript I have an jQuery request which tries to get JSON from the url.

<script type="text/javascript"> 

function doSearch() {   
    $.getJSON("addBook/search.htm", { CHARS: $('#searchBox').val() }, function(data) 
    {   
        alert("Got Response");
        $('#results').text('');
            for (var index in data) {
                $('#results').append('<p>' + data[index].title + '</p>'); 
            }
    });
 }
 </script>

I have a textbox which calls this JS

    <input type="text" id="searchBox" onKeyUp="doSearch();" />

<div id="results">Results</div>

While keying in the controller code is called, but the response that comes back has a status code 406 and says Not Acceptable

What could be the problem here? Also can I set the values of "Accept" header to application/json in the jQuery call? If so how?

I am using a locale resolver to resolve the locale. Could this be a problem?

Thanks Dhanush

Community
  • 1
  • 1
Dhanush Gopinath
  • 5,652
  • 6
  • 37
  • 68

1 Answers1

2

Make sure you have jackson and jackson-mapper jars on your classpath.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • I have jackson core in my POM. Isn't that enough? Or do i need to add all of them ` org.codehaus.jackson jackson-core-lgpl 1.7.4 ` – Dhanush Gopinath Apr 28 '11 at 11:09
  • @dhanush check your `WEB-INF/lib`. Is it there ? – Bozho Apr 28 '11 at 11:11
  • Oh definitely it is there . What I meant was I have only jackson-core-lgpl-1.7.4.jar in the lib got downloaded through the POM.xml file (as dependency) for my maven project. Isn't that enough? – Dhanush Gopinath Apr 28 '11 at 11:26
  • 1
    researched some more and figured out that u need to add jackson mapper also to classpath . The pom dependecy ` org.codehaus.jackson jackson-mapper-lgpl 1.7.4 ` was added and the application was redeployed. Now works like charm. Thanks – Dhanush Gopinath Apr 28 '11 at 11:36