我刚刚创建了我的 web 项目 (JSP/Servlets) 的 war 文件。
项目名称:TestApp
当我在 Tomcat 7 中部署它时,我会这样运行它:
localhost:8080/TestApp/ 或 www.maypage.com/testApp/
好的,一切正常,但我需要在没有项目名称的情况下运行它,就像这样:
localhost:8080 和托管 www.maypage.com
我该怎么做?
谢谢。
我正在优化 jsp/servlet 托管,它们具有该配置选项。你知道这样的托管吗?
为了在不使用应用程序名称的情况下访问您的应用程序,您需要将其部署为根应用程序。有多种方法可以实现它,相关答案对其进行了很好的描述。
Setting default application in tomcat 7
从以上链接复制的内容:
First Method:
first shutdown your tomcat [from the bin directory (sh shutdown.sh)]
then you must delete all the content of your tomcat webapps folder (rm
-fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]
Second Method:
leave your war file in CATALINA_BASE/webapps, under its original name
- turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. explicitly define all application Contexts in
server.xml, specifying both path and docBase. You must do this,
because you have disabled all the Tomcat auto-deploy mechanisms, and
Tomcat will not deploy your applications anymore unless it finds their
Context in the server.xml.
Note:
that this last method also implies that in order to make any change to
any application, you will have to stop and restart Tomcat.
Third Method:
Place your war file outside of CATALINA_BASE/webapps (it must be
outside to prevent double deployment). - Place a context file named
ROOT.xml in CATALINA_BASE/conf//. The single element in this context
file MUST have a docBase attribute pointing to the location of your
war file. The path element should not be set - it is derived from the
name of the .xml file, in this case ROOT.xml. See the Context
Container above for details.