java - Tomcat - 将项目文件夹设为 Web 根目录

标签 java jsp tomcat

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

查看其他有类似问题和类似答案的人 here , herehere

另见 Apache Tomcat Configuration Reference - Context

关于java - Tomcat - 将项目文件夹设为 Web 根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4044129/

相关文章:

java - 在 fragment 中裁剪图像

java - 插入和恢复 BLOB 值 SubType = 文本字段 Firebird Java

java - 在 Spring MVC 中重用模板页面

jsp - 从 jsp 输出中去除空格

java - 如何在 Tomcat 中读取我的 webapp 上下文之外的属性文件

java - 是否可以在新的 tomcat 上运行旧的 java web 应用程序

java - JFreeChart 将数组加载到数据集中

java - 如何从 Java 代码禁用 log4j 日志记录

java - jquery.js 没有在 Tomcat 中加载

java - Spring文件上传引导问题