且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将我的 web 应用程序设置为 ROOTfor localhost:8080

更新时间:2023-11-17 23:30:34

获取根上下文的最简单方法是将应用程序的目录从 webapps/site 重命名为 webapps/ROOT 并重启Tomcat.如果您的默认 webapps 文件夹中已经有一个 ROOT 应用程序,那么您需要创建另一个主机,因为每个主机可能只有一个根上下文应用程序.

另一种选择(同样,如果您在 webapps 下还没有 ROOT 应用程序)是编辑您的 conf/server.xml 文件并添加您的上下文默认 中的元素:

如果你想创建一个单独的主机,那么你需要在server.xml中定义第二个,例如,>

<Host name="anotherhost" appBase="webapps_anotherhost"></Host>

要使上述工作正常运行,您需要在默认主机的 webapps 文件夹旁边创建一个 webapps_anotherhost 文件夹作为同级文件夹,然后将 WAR 放入该文件夹,可以是名为 ROOT 的分解目录,也可以是名为 ROOT.war 的压缩 WAR.然后重新启动 Tomcat 并在 http://anotherhost:8080 浏览您的应用程序(当然,您还将获得一个 hosts 文件条目).

这些只是众多选项中的一小部分.Tomcat 文档对这些内容进行了相当详细的介绍.您可以在 http://tomcat.apache.org/ 找到适用于您的 Tomcat 版本的文档.>

I've got a webapp in my Tomcat/webapps directory. My app's directory is "site" and is showing as http:localhost:8080/site

I'd like to have the site show as http://localhost:8080/

I've read the docs and tried creating a ROOT.xml file in my Tomcat/conf/Catalina/localhost directory to create a ROOT context path but the connection isn't being made.

Can someone nudge me in the right direction? Here's the content of that ROOT.xml file.

<Context  docBase="site" path="/"> </Context>

The easiest approach to getting root context would be to simply rename your app's directory from webapps/site to webapps/ROOT and restart Tomcat. If there's already a ROOT app in your default webapps folder, then you need to create another Host, because there may be only one root context app per Host.

Another option (again, if you don't already have a ROOT app under webapps) would be to edit your conf/server.xml file and add your context element within the default <Host>:

<Context path="" docBase="site" />

If you'd like to create a separate host, then you'll need to define a second <Host> in server.xml, e.g.,

<Host name="anotherhost" appBase="webapps_anotherhost"></Host>

For the above to work, you'd need to create a webapps_anotherhost folder as a sibling folder next to your default host's webapps folder, and then drop your WAR in that folder, either as an exploded directory named ROOT or a compressed WAR named ROOT.war. Then restart Tomcat and browse your application at http://anotherhost:8080 (you'll also a hosts file entry, of course).

These are just a few of the many options. The Tomcat docs are fairly detailed about this stuff. You can find the docs for your version of Tomcat at http://tomcat.apache.org/.