[英]Tomcat - making a project folder the web root
I have this folder under Tomcat webapps/mysite
which is where all my JSPs and other things are located. 我在Tomcat webapps/mysite
下有这个文件夹,这是我所有的JSP和其他东西所在的位置。 To access this folder I go to http://blah.com/mysite and it works just fine. 要访问此文件夹,请访问http://blah.com/mysite ,它运行正常。 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
. 然而(因为样式表和图像静态连接到根/
)我必须这样做,以便当我去http://blah.com/它将加载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? 我尝试了许多不同的东西,包括上下文和在server.xml
设置绝对路径......似乎没什么用,每当我去http://blah.com/它仍然试图加载ROOT文件夹...什么的发生在这里?
The solution I use is to set this in your Tomcat server.xml
我使用的解决方案是在Tomcat server.xml
设置它
Add a <Context>
element within the <Host>
like below which sets your mysite
as the default web app. 在<Host>
添加<Context>
元素,如下所示,将mysite
设置为默认Web应用程序。 Note the empty path=""
which makes it the default. 请注意空path=""
,这使其成为默认path=""
。
<Context docBase="mysite" path="" />
Attributes of Context Container from the Tomcat docs: Tomcat文档中的Context Container的属性:
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. docBase您可以为此目录或WAR文件指定绝对路径名,或者为拥有主机的appBase目录指定路径名。
path All of the context paths within a particular Host must be unique. path特定主机中的所有上下文路径必须是唯一的。 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. 如果指定空字符串(“”)的上下文路径,则表示您正在为此主机定义默认Web应用程序,该应用程序将处理未分配给其他上下文的所有请求。
See others who have had similar question and the similar answer here , here and here 在 这里和这里看到其他有类似问题和类似答案的人
See also Apache Tomcat Configuration Reference - Context 另请参阅Apache Tomcat配置参考 - 上下文
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. 最简单的方法是将webapps / ROOT的内容替换为Web应用程序的内容。
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 有关其他解决方案,请访问以下网站: 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 's awnser works but lacks a step. https://stackoverflow.com/users/1123501/george-siggouroglou的awnser工作,但缺乏一步。
Without the deletion, it may not work. 没有删除,它可能无法正常工作。 Tested with docker. 用docker测试。
You can rename your war from something.war == to ==> ROOT.war . 你可以从something.war ==到==> ROOT.war重命名你的战争。
So, tomcat will unpack the war and will create the folder ROOT for it. 因此,tomcat将解压缩战争并为其创建ROOT文件夹。
It is a trick that is working on tomcat 8 also. 这也是一个在tomcat 8上工作的技巧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.