Results 1 to 2 of 2

Thread: Issue wtih @RequestMapping

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Default Issue wtih @RequestMapping

    My Handler method mapping is defined as below.

    Code:
    @RequestMapping(value = "{categoryPath}/category.action", method = RequestMethod.GET)
    	public ModelAndView showCategory(@PathVariable("categoryPath") final String category, final HttpServletRequest request,
    			final HttpServletResponse response) {
    //Biz Logic
    }
    My issue is that, the request mapping does not match URIs of the form abcd/efgh/category.action. However, it matches abcd/category.action.

    I tested out the mapping with UriTemplate class like below:

    Code:
    final UriTemplate template = new UriTemplate("{category}/category.action");
    
    		System.out.println(template.match("abcd/efgh/category.action"));
    The output generated is:

    Code:
    {category=abcd/efgh}
    So then why does my request mapping not work with abcd/efgb/category.action ?

    I use spring 3.

  2. #2
    Join Date
    Apr 2011
    Posts
    2

    Post

    Okay, I figured out the reason.

    DefaultAnnotationHandlerMapping which is registered by default in DispatcherServlet uses AntPathMatcher to do the pattern matching.

    The logic adopted is roughly as below:

    Split the pattern string and the path string using the path separator as the delimiter(the default path separator is '/' )

    So taking the example in the previous post, the pattern will be split into [{categoryPath},category.action] and the path to [abcd,efgh,category.action]

    The logic then attempts to match the elements of the pattern array and path array one-on-one.

    ie, {categoryPath} against abcd [PASS]
    category.action against efgh [FAIL]

    So now I know the reason why url /abcd/efgh/category.action does not match with
    {categorypath}/category.action but I do not know how to frame the pattern for this genuine scenario.

    Ideas anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •