Checking User Agent in Wicket

我是研究僧i 提交于 2019-12-21 17:45:02

问题


I am using wicket 1.5 and I am not able to see in the getClientInfo() method

(WebRequest)RequestCycle.get().getRequest()

I saw the other place this code

WebClientInfo clientInfo = (WebClientInfo)WebRequestCycle.get().getClientInfo();

But I am not able to see any WebRequestCycle in Wicket 1.5.

Any ideas how to check the user agent in Wicket 1.5?


回答1:


The easiest way is to use

WebSession.get().getClientInfo().getUserAgent();

On newer Wicket Versions (6 or newer), you should use:

WebClientInfo clientInfo = new WebClientInfo(getRequestCycle());

System.out.println("Client: " + clientInfo.getUserAgent());
System.out.println("Navigator: " + clientInfo.getProperties().getNavigatorAppName() + ", version " + clientInfo.getProperties().getNavigatorAppVersion()  + ", codName: " + clientInfo.getProperties().getNavigatorAppCodeName() + ", plataform: " + clientInfo.getProperties().getNavigatorPlatform() + ", AppCodName: " + clientInfo.getProperties().getNavigatorAppCodeName());
System.out.println("NavigatorUserAgent: " + clientInfo.getProperties().getNavigatorUserAgent());
System.out.println("Tamanho da tela (Width x Height): " + clientInfo.getProperties().getScreenWidth() + " x "  + clientInfo.getProperties().getScreenHeight() );



回答2:


You can also do:

((WebRequest) getRequest()).getHeader("User-Agent")


来源:https://stackoverflow.com/questions/10728787/checking-user-agent-in-wicket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!