我在 Tomcat webapps/mysite
下有这个文件夹,这是我所有的 JSP 和其他东西所在的位置。要访问此文件夹,我转到 http://blah.com/mysite它工作得很好。但是(因为样式表和图像静态连接到根 /
)我必须这样做,以便当我转到 http://blah.com/ 时它将加载 webapps/mysite
中的内容。
我已经尝试了很多不同的东西,包括上下文和在 server.xml
中设置绝对路径......似乎没有任何效果,无论何时我去 http://blah.com/它仍然尝试加载 ROOT 文件夹...这里发生了什么?
最佳答案
我使用的解决方案是在你的 Tomcat 中设置这个 server.xml
添加 <Context>
<Host>
中的元素就像下面设置你的 mysite
作为默认的网络应用程序。注意空 path=""
这使其成为默认设置。
<Context docBase="mysite" path="" />
Attributes of Context Container from the Tomcat docs:
docBase You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.
path All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts.
关于java - Tomcat - 将项目文件夹设为 Web 根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4044129/