3

The test case given below shows a simple case where I have 2 parameters paramA and paramB.

  • If I call the /paramtest url the paramtest() method is called.
  • If I enter true for paramA, method aTrue() is called.
  • However, when I enter true for both paramA and paramB the method bTrueNotA() is called.

But the 3rd @RequestMapping calls for A=True and B!=true. By my reconing when both parameters are true, aTrue() should be called.

@RequestMapping("paramtest")
@ResponseBody
public String paramtest(){
    return  "<html><head></head><body>" +
                "<form action=paramtest method=post>" +
                    "paramA: <input type=text name=paramA /><br>" +
                    "paramB: <input type=text name=paramB /><br>" +
                    "<input type=submit>" + 
                "</form>" +
            "</body></html>";       
}

@RequestMapping(value="paramtest", params="paramA=true")
@ResponseBody
public String aTrue(){
    return "A=true";
}

@RequestMapping(value="paramtest", params={"paramB=true", "paramA!=true"})
@ResponseBody
public String bTrueNotA(){
    return "B=True; A!=true";
}
3
  • Which version of spring are you using? Commented Mar 14, 2011 at 8:55
  • What happens if you change "paramA!=true" to "!paramA=true"? Commented Mar 14, 2011 at 10:41
  • Good idea. Tried that, but doesn't solve it: When b=true and a=false (or a is nothing, null) paramtest() is called. When I use paramA!=true it calls that method only depending on paramB, but when I do !paramA=true it never calls bTrueNotA(). Commented Mar 15, 2011 at 8:09

1 Answer 1

1

I think it might be a bug in Spring. I tried with the following mappings:

@RequestMapping(value="/paramtest", params={"paramA=true"})
@ResponseBody
public String function A() { return "A"; }

@RequestMapping(value="/paramtest", params={"paramA=true", "paramB=foobar"})
@ResponseBody
public String function B() { return "B"; }

@RequestMapping(value="/paramtest", params={"paramA=!true", "paramB=foo"})
@ResponseBody
public String function C() { return "C"; }

and using your existing form with the following parameters, these were the results I got:

paramA=true A() called as expected

paramA=true, paramB=foobar B() called as expected

paramA=not_true, paramB=foo 404 page, and not C() as expected.

I got this error on the Tomcat console:

WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver 142 - No matching handler method found for servlet request: path '/paramtest', method 'POST', parameters map['paramB' -> array<String>['foo'], 'paramA' -> array<String>['not_true']]

All of this with Spring 3.0.5. Note that the myParam!=myValue was only available from Spring 3.0.4 onwards (the 3.0.3 doc does not list that option). Also, I do not think that !myParam=myValue is valid, as this is not listed in the current 3.0.5 documentation.

Sorry this is not a solution to your problem but wanted to share my investigation :)

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

2 Comments

I appreciate your comments. I've also posted on their forum with no response. I'll post a JIRA about this. It's always good to know that others can re-produce the problem.
This was confirmed as a bug in the JIRA: jira.springsource.org/browse/…

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.