Browse - Programming Tips - In a Java Servlet, how can I check if the browser is Firefox?

Date: 2012oct12
Language: Java

Q.  In a Java Servlet, how can I check if the browser is Firefox?

A.  Here's a method that does that:

boolean isFirefox(HttpServeletRequest req) { final String agent = req.getHeader("User-Agent"); if (agent == null) return false; return agent.indexOf("Firefox") >= 0; }