开发者

404 error on JSON requests in Spring 3

I'm trying to set up a controller in Spring 3 that will hand开发者_高级运维le AJAX requests from the front end. I had a look at this page which explains it very concisely and simply: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/

I was able to get the example application working correctly. However, in my own application it's just getting a 404 when I make a request to the url where it should be...

Here's the Java code I have (which right now just takes a String parameter and returns it):

@RequestMapping(value="/test", method=RequestMethod.GET)
public @ResponseBody String test(@RequestParam String teacherId) {

    return teacherId;
}

When I try and call this via jQuery's getJSON method, I get a 404.

jQuery.getJSON("test", {teacherId:"123"});

I have the tag in my app-servlet.xml, and Maven is taking in 3 Jackson jars (core, jaxrs, and mapper, all versions 1.8.5) and packaging them in the webapp. The only thing I can think of is maybe Spring Security is not allowing access to this path, but this attribute in the should let already authenticated users have access to this: intercept-url pattern="/**" access="ROLE_USER"

So I'm not sure what I'm missing.


I figured out the problem from this post - No mapping found for HTTP request with URI [/WEB-INF/pages/apiForm.jsp]

If I add an extension in the servlet-mapping special to the DispatcherServlet, like so:

<servlet-mapping>
        <servlet-name>palladium</servlet-name>
        <url-pattern>*.json</url-pattern>
</servlet-mapping>

and then add the extension to the request mapping annotation:

 @RequestMapping(value="/test.json", method=RequestMethod.GET)

Things work out fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜