String url = Page.getCurrent().getLocation().toString();
to get the url in the address bar of the vaadin app. But the problem is that the app is redirected from www.mywebsite.freehost.com to www.mywebsite.com and the code that I am using is getting the wrong url. It is getting the old url. I need the url from the redirect. How can I do this? Does anyone know?
I think the JavaScript solution has 2 problems:
(1)
The JavaScript is executed AFTER the server request that is currently processed returns… they are all executed sequentially AFTER THE REQUEST IS DONE
So you can not execute it, and get the result immediately in the server side code.
(2)and because of (1),
you can not return values from the JavaScript
So, in the server side code, you can not get the result of the JavaScript
You can’t return values from JavaScript, true, but you can add a function callback with JavaScript.getCurrent().addFunction(), which you can then use to get the value to your server-side code. Not the most elegant solution, but it works.
I am redirecting my app from openshift to login.mywebsite.com. The code that you provided is giving me the url for openshift, and not for login.mywebsite.com. Do you have a work around for this?
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.