使用 tomcat 文件夹之外的位置存储和访问 Tomcat 8 中的图像文件 - GNU Linux OS

Using locations outside of tomcat folder to store and access Image files within Tomcat 8 - GNU Linux OS

我是 运行 一个网页 + Tomcat 中的一些 ws,即 GNU Linux OS 上的 运行。该页面将在搜索图像后显示图像,实际图像位于 webapp/appname 文件夹内的文件夹中。最近系统中的免费 space 已经用完了,所以我向系统管理员询问了更多 space,作为回应,他们添加了一个新的 NetApp 卷并将其安装在 /data 文件夹中。它在 Tomcat 文件夹之外,我无法访问它。环顾四周,我发现了这个网站:

Serving static content (including web pages) from outside of the WAR using Apache Tomcat

但这种解决方案适用于当您想通过 url 访问图像时,我显示的图像显示在滑块中并指向 tomcat 中的文件夹。我还读到我可以为所有文件创建一个符号链接,但这行得通吗?滑块 bootstrap 旋转木马会起作用吗?轮播人口是用 javascript 完成的。

有人知道如何解决这个问题吗?

干杯,

es

经过一些搜索和阅读,我找到了适用于 Tomcat 的解决方案 8. 为了能够在 Tomcat 文件夹之外的文件夹中存储和访问图像(文件),您需要执行以下操作:

1- 在 conf/server.xml 中的 <host> 节点中添加以下行:

<Context docBase="path to the location outside of tomcat" path="path  within tomcat"/>

2- 在 conf/context.xml 中的 <Context> 块中添加以下内容

<Resource allowLinking="true">

3- 在应用程序 META-INF/context.xml 中添加上面的内容,在我的例子中它看起来像这样

<?xml version="1.0" encoding0"UTF-8"?>
<Context path"/myapp">
 <Resource allowLinking="true">
</Context>

4- 为位于外部文件夹中的所有文件创建一个symlink,您可以运行以下命令

ln -s /path to other location/* ./images/

图像是我的网络应用程序中的文件夹。在此之后,对于外部位置中的每个文件,将在 images 文件夹中创建一个 link。此解决方案的唯一问题是每次更新应用程序或添加新图像时,您都需要再次创建 symlink(s)。

希望能帮到你,干杯

es。