我在 Tomcat webapps/mysite
下有这个文件夹,这是我所有 JSP 和其他内容所在的位置。要访问此文件夹,我转到 http://blah.com/mysite ,它工作得很好。但是(由于样式表和图像静态连接到根 /
)我必须这样做,以便当我转到 http://blah.com/ 它将加载 webapps/mysite
中的内容。
我尝试了很多不同的事情,包括上下文和在 server.xml
中设置绝对路径...每当我访问 http://blah.com/ 它仍然尝试加载 ROOT 文件夹......这里发生了什么?
I have this folder under Tomcat webapps/mysite
which is where all my JSPs and other things are located. To access this folder I go to http://blah.com/mysite and it works just fine. However (because of stylesheets and images statically connected to the root /
) I have to make it so that when I go to http://blah.com/ it will load the stuff inside webapps/mysite
.
I've tried many different things including contexts and setting the absolute path in server.xml
... nothing seems to work, whenever I go to http://blah.com/ it still tries to load the ROOT folder... what's happening here?
发布评论
评论(4)
我使用的解决方案是在 Tomcat
server.xml
中进行设置,在
中添加一个
元素,如下所示它将您的mysite
设置为默认网络应用。请注意空的path=""
,这使其成为默认值。查看其他有类似问题和类似答案的人此处,此处和此处
另请参阅Apache Tomcat 配置参考 - 上下文
The solution I use is to set this in your Tomcat
server.xml
Add a
<Context>
element within the<Host>
like below which sets yourmysite
as the default web app. Note the emptypath=""
which makes it the default.See others who have had similar question and the similar answer here, here and here
See also Apache Tomcat Configuration Reference - Context
有多种方法可以使应用程序成为根应用程序。最简单的方法是将 webapps/ROOT 的内容替换为您的 Web 应用程序的内容。
其他解决方案请参见以下网站:
http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application_.3F
There are a number of ways to make an application the root application. The simplest way is to just replace the contents of webapps/ROOT with the contents of your web application.
For other solutions, please see the following website:
http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application_.3F
https://stackoverflow.com/users/1123501/george-siggouroglou 的 awnser 可以工作,但缺少一个步骤。
如果不删除,可能无法工作。用码头工人测试。
https://stackoverflow.com/users/1123501/george-siggouroglou 's awnser works but lacks a step.
Without the deletion, it may not work. Tested with docker.
您可以将您的战争从 something.war == 重命名为 ==>; ROOT.war.
因此,tomcat 将解压该 war 并为其创建文件夹 ROOT。
这个技巧也适用于 tomcat 8。
You can rename your war from something.war == to ==> ROOT.war.
So, tomcat will unpack the war and will create the folder ROOT for it.
It is a trick that is working on tomcat 8 also.