在Vaadin 14应用中通过服务器端的Java获取用户网络浏览器的IP地址 [英] Get the IP address of the user’s web browser via Java on the server-side in a Vaadin 14 app
问题描述
在 Vaadin Flow 中,例如版本14.1,如何获得<用户的网络浏览器通过
In Vaadin Flow, such as version 14.1, how can I get the IP address of the user’s web browser through a Java call on the server-side?
像问题一样, 在Vaadin 7 Web应用程序中获取用户的IP地址和其他客户端信息 ,但对于Vaadin Flow而不是Vaadin 7& 8.
Like the Question, Get user’s IP address, and other client-side info in Vaadin 7 web app, but for Vaadin Flow instead of Vaadin 7 & 8.
推荐答案
WebBrowser::getAddress
WebBrowser::getAddress
In Vaadin Flow, use the class WebBrowser::getAddress
to get the user's IP address.
要获取 WebBrowser
对象,询问当前 VaadinSession
对象.
To get a WebBrowser
object, ask the current VaadinSession
object.
String ipAddress = VaadinSession.getCurrent().getBrowser().getAddress() ;
WebBrowser
对象还保存有关客户端浏览器类型和版本的信息,它们是当前默认的操作系统,浏览器处理现代Vaadin Flow网络应用程序的功能等.
The WebBrowser
object also holds information about the client’s browser kind and version, their current default Locale
, host OS, browser’s ability to handle modern Vaadin Flow web apps, and more.
顺便说一句,在Vaadin 14中,您可以在客户端上运行JavaScript片段.因此,这可能是获取有关您的客户端用户的浏览器和主机的更多详细信息的方式. Vaadin 15的加入大大增强了对在客户端上执行JavaScript的支持,同时保持了与服务器上Vaadin Flow Java运行时的通信.
By the way, in Vaadin 14 you can run snippets of JavaScript on the client. So that might be a way to obtain even more details about the browser and host of your client user. And coming in Vaadin 15 is greatly enhanced support for executing in JavaScript on the client while maintaining communications with the Vaadin Flow Java runtime on the server.
这篇关于在Vaadin 14应用中通过服务器端的Java获取用户网络浏览器的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!