Get the IP address of the user’s web browser via Java on the server-side in a Vaadin 14 app
Asked Answered
T

1

2

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.

Takara answered 4/2, 2020 at 23:3 Comment(0)
T
5

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.

Takara answered 4/2, 2020 at 23:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.