[英]Wicket: Get Browser Information
How do I get information about the browser in a Java/Wicket/Maven Project? 如何在Java / Wicket / Maven项目中获取有关浏览器的信息?
Greetings 问候
You can capture the browser information using the following code 您可以使用以下代码捕获浏览器信息
getApplication().getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
getApplication()getRequestCycleSettings()setGatherExtendedBrowserInfo(真)。。
WebClientInfo w = (WebClientInfo)getWebRequestCycle().getClientInfo();
WebClientInfo w =(WebClientInfo)getWebRequestCycle()。getClientInfo(); ClientProperties cp = w.getProperties();
ClientProperties cp = w.getProperties();
// do something with the data cp.getNavigatorAppName();
//对数据执行某些操作cp.getNavigatorAppName();
cp.getNavigatorAppCodeName();cp.getNavigatorAppCodeName();
cp.getNavigatorAppVersion();cp.getNavigatorAppVersion();
cp.getBrowserVersionMajor();cp.getBrowserVersionMajor();
cp.getBrowserVersionMinor();cp.getBrowserVersionMinor();
Exerpt taken from WICKET Documentation 摘自WICKET文档
EDIT Updated from comments. 编辑更新了评论。
The above code is for Wicket 1.4.x. 以上代码适用于Wicket 1.4.x. For newer versions of Wicket replace getWebRequestCycle() with getRequestCycle()
对于较新版本的Wicket,使用getRequestCycle()替换getWebRequestCycle()
If there is no getClientInfo()
on getRequestCycle()
(like there wasn't for me either), you could try the answer to this question: 如果在
getRequestCycle()
getClientInfo()
上没有getClientInfo()
(就像我没有那样),你可以试试这个问题的答案:
Checking User Agent in Wicket 检查Wicket中的用户代理
WebSession.get().getClientInfo();
It worked for me. 它对我有用。
Wicket 6.x also provides org.apache.wicket.ajax.AjaxClientInfoBehavior
. Wicket 6.x还提供了
org.apache.wicket.ajax.AjaxClientInfoBehavior
。 A demo of it can be seen at: http://www.wicket-library.com/wicket-examples-6.0.x/ajaxhellobrowser/ 它的演示可以在以下网址看到: http : //www.wicket-library.com/wicket-examples-6.0.x/ajaxhellobrowser/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.