I’m developing a GWT App which generates reports for download. When I launch in Eclipse it has an URL like this:
http://127.0.0.1:8888/MyApp.html
But when I package my app for deployment in a web server (i.e. Tomcat) my URL is like this:
http://localhost:8080/MyApp/MyApp.html
Is there any way to get the app’s base URL? Like http://localhost:8080/MyApp/ in the second case?
The
doPostmethod onRemoteServiceServletis passed theHttpServletRequestsent by the client.HttpServletRequesthas a number of methods available that can construct the base URL of the client’s request. HttpServletRequest.getRequestURL() retrieves the whole URL from the request. If you just want the base URL without the page name, you could instead use a combination of getRemoteHost, getRemotePort, and getServletPath.Example: