Issue
After following this question, I added HttpServletRequest
parameter to my method. But I added nearly 20 IF conditions to have a complete case-insensitive URL.
This is a completely painful and ugly way of coding, I know. I request anyone to give an amazing solution to this.
I need to have a case-insensitive request-parameter. The request parameter which is sending is orgID
. This parameter would be coming in different ways. E.g. Orgid
, oRgid
, orGid
, orgID
... and so-on
I cannot do this directly as request.getParamter ("orgID")
. For this, I am adding many if conditions. :-( as I said, completely ugly coding.
Solution
Though this concept is wrong(it is not good to get the params in different cases) the following code snippet works:
String getCaseInsensitiveParameter(HttpServletRequest request){
Map params = request.getParameterMap();
Iterator i = params.keySet().iterator();
while ( i.hasNext() )
{
String key = (String) i.next();
String value = ((String[]) params.get( key ))[ 0 ];
if ("orgid".equals(key.toLowerCase()) {
return value;
}
}
return null;
}
Answered By - Arun