gpt4 book ai didi

web-services - 将外部目录映射到 web.xml

转载 作者:行者123 更新时间:2023-12-03 23:22:49 26 4
gpt4 key购买 nike

有没有一种简单的方法可以映射 web.xml 或其他部署描述符(jetty.xml 等)文件中的目录?

例如,如果我有一个目录/opt/files/,有没有一种方法可以通过访问 http://localhost/some-mapping/ 来访问其文件和子目录。 ?我突然想到应该有一些简单的方法可以做到这一点,但我一直无法找到方法(通过谷歌,stackoverflow 等)。我发现的只是模仿文件服务器的 servlet,这不是我想要的。

作为引用,我在 AIX 机器上使用 jetty。

最佳答案

不知道如何使用 Jetty 来做到这一点,但在 Tomcat 中你可以添加一个新的 <Context>server.xml :

<Context docBase="/opt/files" path="/files" />

这样可以通过 http://example.com/files/... 访问它。看看 Jetty 是否存在类似的东西。

更新:谷歌搜索后,“正常的Java代码”等价物将类似于:

WebAppContext files = new WebAppContext("/opt/files", "/files");
Server server = new Server(8080);
server.setHandler(files);
server.start();

现在尚未将其翻译为 jetty.xml味道。我根据网上找到的文档和示例进行了一些猜测,所以不要让我相信它:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="webApp">/opt/files</Set>
<Set name="contextPath">/files</Set>
</Configure>

另一种可能性可能是这样的:

<Configure class="org.mortbay.jetty.Server">
<Call name="addHandler">
<Arg>
<New class="org.mortbay.jetty.webapp.WebAppContext">
<Arg name="webApp">/opt/files</Arg>
<Arg name="contextPath">/files</Arg>
</New>
</Arg>
</Call>
</Configure>

关于web-services - 将外部目录映射到 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2404528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com