How to hide spring mvc web app name in the browser

2019-07-19 06:13发布

问题:

I have a spring mvc 3.x web app in eclipse where the resource project artifact name is "webapp". So, http://localhost:8080/webapp will load the main home page using tomcat 7 with the eclipse IDE.

However, when I release to tomcat 7.0 to some prod servers I don't want the URL to resolve to http://mywebsite.com/webapp but instead http://mywebsite.com

How can I achieve this?

回答1:

You can follow either of below approaches

  1. Delete existing ROOT/ directory (in webapps) from tomcat and rename your war file to ROOT.war and then deploy it.

  2. Configure the context root in tomcat's conf/server.xml to use your war file (assuming my_war is your war name)

    < Context path="" docBase="my_war" reloadable="true">