Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Getting the URL in the address bar.

Bill Nye
5 years ago Nov 16, 2016 3:21pm
Ying Li
5 years ago Nov 17, 2016 6:49am

Try this:

(1)get the current Vaadin request:

import com.vaadin.server.VaadinService;
VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();

(2)convert it to VaadinServletRequest, and then get the HttpServletRequest from it:

HttpServletRequest httpServletRequest = ((VaadinServletRequest)vaadinRequest).getHttpServletRequest();

(3)get the URL the client used to make the request.

String requestUrl = httpServletRequest.getRequestURL().toString();

I did not test if it work.
So please try it, and tell me if the result is correct

Olli Tietäväinen
5 years ago Nov 17, 2016 6:53am
Ying Li
5 years ago Nov 17, 2016 7:04am
Olli Tietäväinen
5 years ago Nov 17, 2016 7:08am
Bill Nye
5 years ago Nov 18, 2016 12:25pm
Ying Li
5 years ago Nov 20, 2016 12:59pm
Shaini Sinha
2 years ago Dec 19, 2019 8:31pm

Any Idea how to achieve the same in Vaadin 14 (Spring Boot)?

Jonathan Hult
1 year ago May 19, 2020 2:31pm

This Github issue discusses some methods for accessing the current page URL (in Flow, so Vaadin 10+).

It sounds like the current "best" approach is to retrieve it using JavaScript from Location. Here is an example.

UI.getCurrent().getPage().executeJs("return window.location.href").then(String.class, location -> {
	Notification.show(String.format("Location: '%s'", location));

If you only want the path (no host or protocol), then use window.location.pathname. If you only want the query string, then use window.location.search.