My Util.java contains following method:
public static boolean isAndroid(HttpServletRequest request) {
boolean retVal = false;
String browser = request.getHeader("User-Agent");
if (browser != null && !browser.trim().equals("") && browser.contains("Android")) {
retVal = true;
}
return retVal;
}
And I’ve below code in BaseAction.java (it also has request variable of type HttpServletRequest) which extends ActionSupport & implements ServletRequestAware, ServletResponseAware.
public boolean isAndroid(){
return Util.isAndroid(request);
}
Now, I want to check in JSP if device is android & if it is perform certain action, so I’m using below code:
<s:if test="%{#android=='false'}">
<a href="/myUrl"></a>
</s:if>
<s:else>
....
</s:else>
But the above code doesn’t seem to work. Can any one suggest why its not working & if there is another way to check in JSP to see if user is using Android browser?
Thanks!
You’re comparing against the string
"false"but should be checking against an actual boolean, and can use<s:if test="android">or<s:if test="!android">as required.Also, you’re prefixing the property name with a
#, which is not necessary for values pushed on to the stack–the#character is only for named values in the stack context.All that said, why bother doing it that way?