简体   繁体   English

如何使用JSF获取用户的浏览器ID?

[英]How to get user's browser id using JSF?

Is it possible to get the user's browser id number using JSF? 是否可以使用JSF获得用户的浏览器ID号? I use JBoss 7 for application server. 我将JBoss 7用于应用程序服务器。

The browser's user agent string is available as HTTP request header with the name User-Agent . 浏览器的用户代理字符串可用作HTTP请求标头,名称为User-Agent The request headers are in JSF available by ExternalContext#getRequestHeaderMap() : 请求标头在JSF中,由ExternalContext#getRequestHeaderMap()

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

No need to haul the raw Servlet API from under the JSF hoods. 无需从JSF引擎下拖出原始Servlet API。 Always look at the javadoc of ExternalContext first whenever you need to have access to the HTTP servlet request or response. 每当您需要访问HTTP Servlet请求或响应时,请始终先查看ExternalContext的javadoc。

Keep in mind that request headers (as everything else in a HTTP request) are fully controllable by the enduser. 请记住,请求标头(与HTTP请求中的其他所有内容一样)由最终用户完全控制 So never assume the information to be correct and valid. 因此,切勿假设信息正确无误。 Use it for statistics only. 仅将其用于统计。 If you need to do feature detection, strongly prefer client side languages like JavaScript and/or CSS if possible. 如果需要进行特征检测,请尽可能使用JavaScript和/或CSS等客户端语言。 They can do that much more reliably. 他们可以更可靠地做到这一点。

您可以从request读取user-agent标头,以获取有关浏览器的详细信息

((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getHeaders();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在jsf中获取当前视图ID和先前视图ID - how to get current view id and previous view id's in jsf 如何使用JSF和WebSphere获得用户电子邮件? - How to get user email using JSF and WebSphere? 如何获取用户刷新时更新的jsf列表 - how to get a jsf list updated on user refresh 如何在JSF中验证唯一性并向用户发送消息? - How to validate uniqueness in JSF and get a message to the user? 如何查询Ldap以获取结果中的用户属性并将其用于JSF2.0表单的自动填充 - How to query Ldap to get user's attributes in result and use it in auto fill in JSF2.0 form 如何获取使用C#在浏览器中单击的webElement ID? - how to get webElement ID which was clicked at browser using C#? 如何使用JNI获取浏览器上当前活动选项卡的进程ID - How to get process id of currently active tab on browser using JNI 如何从响应JSON获取用户的ID - How to get user's id from response json 如何获得用户在列表视图上单击的商品的唯一ID - How to get the user's unique id of the item clicked on listview JSF,Spring和Hibernate-如何使用ID GET参数填充编辑表单 - JSF, Spring and Hibernate - how to populate edit form with id GET param
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM