检查在检票用户代理(Checking User Agent in Wicket)

2019-07-29 12:39发布

我使用的检票1.5,我不能够在看到getClientInfo()方法

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

我看到其他地方的代码

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

但我无法看到任何WebRequestCycle在检票1.5。

任何想法如何检查用户代理检票1.5吗?

Answer 1:

最简单的方法是使用

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

在较新的版本检票(6或更高版本),你应该使用:

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() );


Answer 2:

你也可以这样做:

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


文章来源: Checking User Agent in Wicket