GWT getting application path

I have a GWT application which, when deploying the local home page after the application starts, is localhost: 8888 / myapp.html, but when we deploy it on the server, after starting the application on the main page 107.20.239.198:8080/myapp/myapp.html.

Now all the related paths to which my application fails. Places where I need the exact path, I cannot understand it. As now, the path is different. For example, when I click on a specific widget in my application → It redirects to the path "/ # +" place number 1 "+" place number 2 "

But now it does not work when deploying to the server, since now it needs the path → '/ myapp / # + "place no.1" + "place no.2"'.

So how can I make it general so that I can handle both conditions.

Can anyone help me with this?

PS I hope that I can express my problem well, otherwise you can comment on it so that I can better explain it.

+4
source share
3 answers

From your local URL, as you mentioned above, it looks like you are running it on the AppEngine server. It is better to deploy your application on Tomcat first on your local computer. And make sure everything is working fine. These are a few methods that you can use to get relative/absolute urls when you run the application.

 GWT.getHostPageBaseURL(); GWT.getModuleBaseURL(); GWT.getModuleName(); 

Hope this helps.

+4
source

You should use relative paths in your application relative to your context. Using request.getContextPath() , you can get the correct context path. But if you use "/" in your code, you will always refer to your context path, no matter what the context is. Thus, to create a link to the internal page, you will use /internal.html. On your local machine it will be converted to localhost: 8888 / internal.html, but on the server it will be: 107.20.239.198:8080/myapp/internal.html.

+1
source

As @Anuj Kulkarni mentioned, you really should use a relative path, because otherwise you will always get these problems. But I had one specific problem when I could not do this. Therefore, if you like, you can use:

 if (!GWT.isProdMode()) 

Here you can define different URLs for your development and deployment environment. But if you use this more than once in your code, it means that you are doing something wrong.

+1
source

All Articles