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

标签 web-services mapping external web.xml

有没有一种简单的方法可以映射 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/

相关文章:

javascript - 这些 window.external 调用是什么意思?

xcode - 通过外部硬盘上的 Git 跟踪更改的文件

android - 将 G-WAN 用于 Web 服务

java - 设置默认的 SocketFactory

php - 未找到 Doctrine 映射案例

entity-framework - 将EF核心约定和DBFunction混合用于JObject属性

c# - .Net 代码捕获来自 .asmx 网络服务的 HTTP 500 错误响应

java - 使用 SMSLib 和 Web 服务发送 SMS

inheritance - EF4.1 Exception creating Database with table-per-hierarchy 继承

angularjs - 在 Angular 指令中的外部模板 (templateURL) 上使用 $compile