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

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

问题描述

我在Tomcat webapps / mysite 下有这个文件夹,这是我所有的JSP和其他东西所在的位置。要访问此文件夹,我转到 http://blah.com/mysite ,它运行正常。但是(因为样式表和图像静态连接到根 / )我必须这样做,以便当我去 http://blah.com/ 它会加载 webapps / mysite 中的内容。

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.

我尝试过许多不同的事情,包括上下文和设置 server.xml中的绝对路径 ......无论何时我都去看似没什么用要 http://blah.com/ ,它仍然会尝试加载ROOT文件夹......这里发生了什么?

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?

推荐答案

我使用的解决方案是在Tomcat中设置它 server.xml

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

< Host> < Context> 元素c $ c>如下所示将 mysite 设置为默认的Web应用程序。请注意空 path =,这使其成为默认值。

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="" /> 

来自Tomcat文档,

From the Tomcat docs,


如果指定
空字符串()的上下文路径,则为
主机定义
默认Web应用程序,它将处理所有请求
未分配给其他上下文

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

查看其他有类似问题和类似答案的人在其中 here 此处

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

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

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