java - 在 Tomcat 上部署 war 文件并在没有项目名称的情况下运行

标签 java jsp tomcat servlets tomcat7

<分区>

我刚刚创建了我的 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.

关于java - 在 Tomcat 上部署 war 文件并在没有项目名称的情况下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18413723/

相关文章:

java - 线程在多核环境中是否更高效?

java - 在计时器后关闭 android View

jsp - 使用从 Servlet 中的数据库获取的值填充 JSP 中的 HTML <select> 下拉列表

ruby-on-rails - 在 Windows 中将 JRuby war 文件部署到 Tomcat

java - 二进制字符串转文本字符串Java代码

使用 kernal32 VirtualQueryEx 的 Java JNA 返回零(无成功错误代码)

javascript - 在页面加载时在编辑 jsp 页面的下拉列表中显示所选值(Spring MVC)

java - jsp下拉列表不自动选择正确的值

java - 当我运行超过 1 个几乎完全相同的 java servlet 时,为什么我的服务器会崩溃?

tomcat - 简单的 Tomcat 问题 在 Webapps 文件夹下创建一个新文件夹