views:

54

answers:

1

I'm taking my first steps to explore Spring MVC 3 (annotation driven) and the JSON functionality that it supports.

1) In my JSP page I want to click a link that retrieves JSON

$("a[class=simple2]").click(function() {
      $.getJSON("checkName.html", function(contacts) {
           alert(contacts);
       });
       return false;
});

2) The method that gets called that should return the JSON

 @RequestMapping(value = "/checkName")
 public @ResponseBody Contact checkName() {
     List<Contact> contacts = this.userService.retrieveAll();
     return contacts.get(0);
 }

When this return gets triggered the DispatcherServlet catches an exception:

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

After searching some I read that the Jackson jar (http://wiki.fasterxml.com/JacksonDownload jackson-all-1.6.1.jar) needs to be added to the project (or server? I tried both)

Any ideas? Thanks!

+1  A: 

It seems a fresh start this morning (and other posts here) already got the problem fixes!

I only have jackson-all-1.6.1.jar added now to my project and added to my dispatcher xml which seems all that was necessary...

But I'll quickly add another question then! :) I'm having trouble accessing javascript files (and probably any other files aswell) in my project. From WEB-INF/jsp/home.jsp I wanne to call my javascript file in /WEB-INF/resources/jquery-1.4.3.js

my dispatcher is defined like: < servlet-name>dispatcher< /servlet-name > < url-pattern>/< /url-pattern>

and I've added

script type="text/javascript" src="/resources/jquery-1.4.3.js">

script type="text/javascript" src="/jquery-1.4.3.js">

script type="text/javascript" src="/WEB-INF/resources/jquery-1.4.3.js">

script type="text/javascript" src="SpringMVC/WEB-INF/resources/jquery-1.4.3.js">

< script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery-1.4.3.js">< /script> etc all do not seem to work.

Dozz