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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

I have jackson core in my POM. Isn't that enough? Or do i need to add all of them <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-lgpl</artifactId> <version>1.7.4</version> </dependency>
@dhanush check your WEB-INF/lib. Is it there ?
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?
researched some more and figured out that u need to add jackson mapper also to classpath . The pom dependecy <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-lgpl</artifactId> <version>1.7.4</version> </dependency> was added and the application was redeployed. Now works like charm. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.