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

爱⌒轻易说出口 提交于 2020-02-25 02:27:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!