Search code examples
javatomcaturlxhtmlremote-server

Url Problem while Developing on Localhost and deploy on Remote Virtual Server


I have developed an WebApplication which runs on a Tomcat on my Notebook on Localhost. Now i have the task to deploy the Application to a remote Virtual Server. I coded all the redirects via JSF and a custom Servlet Class.For Example you press a Button and a Method gets called which redirects you to http://localhost:8080/myApp/some.xhtml. But when i Deploy the App to the remote Server i have to change all the redirects because it has now a different URL. Is there a way of mapping these URLS to their counterpart on the remote Server, so i don't have to change every single redirect in the xhtml Files and the Servlet? How is the way to go here?


Solution

  • Suggestion 1.

    Instead of redirecting to http://localhost:8080/myApp/some.xhtml, build the URL from a base URL (e.g. "http://localhost:8080/myApp/") and a path. Then make the base URL a configuration parameter.

    See also: Root URl of the servlet

    Suggestion 2.

    Redirect to "/myApp/some.xhtml" and let the URI resolver deal with it. Assuming that the URI is resolved in the context of the original URL, it should go to the correct place.