Vaadin 中的客户端浏览器检测
我想根据用户代理为我的 Vaadin 应用程序设置不同的主题。 我特别想至少区分移动设备(iPhone、Android...)和桌面网络浏览器。
Vaadin 的 API 揭示了两个有趣的类:
BrowserInfo
似乎可以完成这项工作完全满足我的需求,但通过其 get
方法实例化失败:
SEVERE: javax.servlet.ServletException: ...
Caused by: java.lang.UnsatisfiedLinkError: com.vaadin.terminal.gwt.client.BrowserInfo.getBrowserString()Ljava/lang/String;
也无法找到从我的应用程序内访问 WebBrowser
的方法。
- 我是否选择了正确的浏览器区分方法?
- 为什么访问
BrowserInfo
失败?
I want to set different themes to my Vaadin application, depending on the user agent.
In particular I want to distinguish at least between mobile devices (iPhone, Android,...) and desktop web browser.
Vaadin's API reveals two interesting classes:
BrowserInfo
seems to do the job perfectly for my needs, but fails on instancing via its get
-method:
SEVERE: javax.servlet.ServletException: ...
Caused by: java.lang.UnsatisfiedLinkError: com.vaadin.terminal.gwt.client.BrowserInfo.getBrowserString()Ljava/lang/String;
Couldn't find a way to access WebBrowser
from within my application either.
- Did I choose the right approach for browser distinction?
- Why does accessing
BrowserInfo
fail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如@quickanalysis 所指出的,您必须意识到客户端/服务器端组件的分离。
为了在服务器端获取用户代理字符串,以下代码片段可以完成这项工作:
As @quickanalysis pointed out, you've to be aware of the separation of client-/server-side components.
For getting the user agent string on server-side, the following code snippet does the job:
您试图从哪个类调用此方法? BrowserInfo 在客户端可用,而 WebBrowser 在服务器端可用。看一下包的命名。
From what class you are trying to call this method? The BrowserInfo is available at client-side as WebBrowser ar the server-side. Take a look at the package naming.