问题
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?
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.
回答1:
WebBrowser::getAddress
In Vaadin Flow, use the class WebBrowser::getAddress to get the user's IP address.
To get a WebBrowser object, ask the current VaadinSession object.
String ipAddress = VaadinSession.getCurrent().getBrowser().getAddress() ;
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.
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.
来源:https://stackoverflow.com/questions/60066806/get-the-ip-address-of-the-user-s-web-browser-via-java-on-the-server-side-in-a-va