How to get browser user id using JSF?

Is it possible to get browser user id number using JSF? I am using JBoss 7 for an application server.

+7
source share
2 answers

You can read the user-agent header from request to get detailed browser information

 ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getHeaders(); 
+9
source

The browser user agent string is available as an HTTP request header named User-Agent . Request headers are in the JSF, accessible by ExternalContext#getRequestHeaderMap() :

 ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); String userAgent = externalContext.getRequestHeaderMap().get("User-Agent"); 

No need to extract the raw servlet API from under the JSF shrouds. Always look at javadoc ExternalContext when you need access to an HTTP servlet request or response.

Keep in mind that the request header (like everything else in the HTTP request) is fully controlled by the end user. Therefore, never assume the correctness and reliability of information. Use it only for statistics. If you need to perform feature detection, it is highly recommended that you use client-side languages ​​such as JavaScript and / or CSS, if possible. They can do it much more reliably.

+20
source

All Articles