Am sending data from JSP to controller using query string.
My controller is annotation driven.
The value of the the request parameter should be case-insensitive.
The method which i use for welcome page is
public String welcome(@RequestParam("orgID") String orgID, ModelMap model)
The request parameter "orgID" should be case insensitive. How to do this ?.
I should be able to give the query-string as "orgid" or "orgId". The parameter should be completely case-insensitive. Looking for your help friends.
Thanks in Advance :-)
The parameter should be completely case-insensitive.
Encoded vs Exact Value On the other hand, @RequestParam is encoded.
Method parameters annotated with @RequestParam are required by default. will correctly invoke the method. When the parameter isn't specified, the method parameter is bound to null.
@QueryParam is a JAX-RS framework annotation and @RequestParam is from Spring. QueryParam is from another framework and you are mentioning Spring. @Flao wrote that @RequestParam is from Spring and that should be used in Spring MVC.
It might be nice for Spring to support this, but I can also understand why they wouldn't since it could result in a weakening of an interface contract between a supplier and consumer. In the meantime, here's a fairly straightforward way to take the first value using the parameter name regardless of its case.
String myVal = null;
for (String pname : request.getParameterMap().keySet() ) {
if ( pname != null && pname.toLowerCase().equals("your_lc_pname") ) {
for (String v : request.getParameterValues(pname) ) {
// do something with your value(s)
}
}
}
Another approach would be to have two parameters "orgId" and "orgid" and have the optional.
public String welcome(@RequestParam(value="orgID", required = false) String org_ID, @RequestParam(value="orgid", required=false, String orgid, ModelMap model) {
final String orgId = orgid == null ? org_ID : orgid;
...
}
But if you have control over the parameters I would strongly prefer to just have one consistent way, say org-id and follow it both in the client and the server side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With