Tomcat的extraResourcePaths和访问外部目录的别名的区别

编程入门 行业动态 更新时间:2024-10-21 18:57:36
本文介绍了Tomcat的extraResourcePaths和访问外部目录的别名的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

简单问题:在Tomcat7中,使用extraResourcePaths和别名访问应用程序外的目录有什么区别?

Simple question: In Tomcat7, what's the difference between using extraResourcePaths and aliases to access an directory outside the application?

我可以使用这两个 server.xml 片段中的任何一个,而且它们似乎都可以工作.两者似乎都成功加载了这个 URL:http://localhost/app/images/box.jpg.使用一个比另一个有优势吗?

I can use either of these two server.xml snippets and they both seem to work. Both seem to load this URL successfully: http://localhost/app/images/box.jpg. Is there an advantage to using one over the other?

<Context docBase="Eclipse_Project" path="/app"
        reloadable="true" source="org.eclipse.jst.j2ee.server:Eclipse_Project"
        aliases="/images=D:\path\to\images"/>

<Context docBase="Eclipse_Project" path="/app"
        reloadable="true" source="org.eclipse.jst.j2ee.server:Eclipse_Project">
        <Resources className="org.apache.naming.resources.VirtualDirContext"
                extraResourcePaths="/images=D:\path\to\images"/>
</Context>

推荐答案

这是多种不同方式拉入不属于 WAR 或分解目录的资源的结果.坦率地说,这是一个早该清理的烂摊子.为 Servlet 3.1(即 Tomcat 8)提议的覆盖"(或任何它最终被调用的)特性促使了一次重大清理.当前所有的实现将统一为一个实现.不过它并不漂亮,而且需要一段时间才能完成.

This is the result of having multiple different ways of pulling in resources that aren't part of a WAR or exploded directory. Frankly it is a mess long overdue a clean-up. The 'overlay' (or whatever it ends up being called) feature proposed for Servlet 3.1 (i.e. Tomcat 8) has prompted a major clean-up. All the current implementations will be unified into a single implementation. It isn't pretty though, and it is going to take a while to complete.

别名被视为 Web 应用程序资源的外部.DirContext 在检查其内部资源之前检查别名.因此,当您请求真实路径时,您会得到原始路径.

Aliases are treated as external to the web application resources. The DirContext checks aliases before it checks its internal resources. Hence when you request the real path you get the original.

如果您使用 extraResourcePaths,它们将被视为 Web 应用程序资源的一部分.看起来 Eclipse 已将应用程序资源的副本触发到工作目录.这通常是为了避免文件锁定.由于 extraResourcePaths 被视为 web 应用程序的一部分,它们也会被复制并且 getRealPath() 报告复制的位置,因为这是 Tomcat 提供资源的位置.

If you use extraResourcePaths they are treated as part of the web application resources. It looks like Eclipse has triggered a copy of application resources to the work directory. This is usually done to avoid file locking. Since the extraResourcePaths are treated as part of the webapp, they get copied too and getRealPath() reports the copied location since that is where Tomcat is serving the resources from.

这篇关于Tomcat的extraResourcePaths和访问外部目录的别名的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 04:29:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1389324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   区别   目录   Tomcat   extraResourcePaths

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!