Tomcat - 将项目文件夹设为 Web 根目录 [英] Tomcat - making a project folder the web root

查看:41
本文介绍了Tomcat - 将项目文件夹设为 Web 根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Tomcat webapps/mysite 下有这个文件夹,这是我所有的 JSP 和其他东西所在的位置.要访问这个文件夹,我去 http://blah.com/mysite 并且它工作得很好.但是(因为样式表和图像静态连接到根 /)我必须这样做,以便当我去 http://blah.com/ 它将加载 webapps/mysite 中的内容.

我尝试了很多不同的事情,包括上下文和在 server.xml 中设置绝对路径......似乎没有任何工作,每当我去 http://blah.com/ 它仍然尝试加载 ROOT 文件夹......这里发生了什么?

解决方案

我使用的解决方案是在你的 Tomcat server.xml

中设置这个

中添加一个 元素,如下所示,将您的 mysite 设置为默认网络应用程序.请注意空 path="" 使其成为默认值.

<块引用>

来自 Tomcat 文档的上下文容器的属性:

docBase 您可以为此目录或 WAR 文件指定绝对路径名,或相对于 appBase 目录的路径名拥有主机的.

path 特定主机内的所有上下文路径必须是唯一的.如果指定空字符串 ("") 的上下文路径,则定义此主机的默认 Web 应用程序,它将处理所有未分配给其他上下文的请求.

看看其他有类似问题和类似答案的人 此处此处这里

另请参阅 Apache Tomcat 配置参考 - 上下文

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?

解决方案

The solution I use is to set this in your Tomcat server.xml

Add a <Context> element within the <Host> like below which sets your mysite as the default web app. Note the empty path="" which makes it the default.

<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.

See others who have had similar question and the similar answer here, here and here

See also Apache Tomcat Configuration Reference - Context

这篇关于Tomcat - 将项目文件夹设为 Web 根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆