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

Web services 将外部目录映射到web.xml,web-services,mapping,external,web.xml,Web Services,Mapping,External,Web.xml,在web.xml或其他部署描述符(jetty.xml等)文件中映射目录是否有一种简单的方法 例如,如果我有一个目录/opt/files/,有没有一种方法可以访问它的文件和子目录?我觉得应该有一些简单的方法来做到这一点,但我还没有找到方法(通过谷歌、stackoverflow等)。我发现的只是模仿文件服务器的servlet,这不是我想要的 作为参考,我在AIX机箱上使用jetty。我不知道您是否可以将其作为URL映射,但是您的web.xml文件所在的同一目录中的文件和文件夹将可以按照您描述的方式进

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

例如,如果我有一个目录/opt/files/,有没有一种方法可以访问它的文件和子目录?我觉得应该有一些简单的方法来做到这一点,但我还没有找到方法(通过谷歌、stackoverflow等)。我发现的只是模仿文件服务器的servlet,这不是我想要的


作为参考,我在AIX机箱上使用jetty。

我不知道您是否可以将其作为URL映射,但是您的web.xml文件所在的同一目录中的文件和文件夹将可以按照您描述的方式进行访问,尽管您无法控制webapp下的映射


这是否符合您的需要?

在做了更多的修改之后,最好的方法是在上下文目录中部署一个描述符,如下所示

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- Configuration of a custom context. -->
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
    <Call class="org.eclipse.jetty.util.log.Log" name="debug">
        <!-- The default message to show if our context breaks. -->
        <Arg>Configure context.xml</Arg>
    </Call>
    <!--
        The context path is the web location of the context in relation to the
        server address.
    -->
    <Set name="contextPath">/context</Set>
    <!--
        The resource base is the server directory to use for fetching files.
    -->
    <Set name="resourceBase">/path/to/files/on/server</Set>
    <Set name="handler">
        <New class="org.eclipse.jetty.server.handler.ResourceHandler">
            <Set name="directoriesListed">true</Set>
            <!-- For now we don't need any welcome files -->
            <!--
                <Set name="welcomeFiles"> <Array type="String">
                <Item>index.html</Item> </Array> </Set>
            -->
            <!--
                The cache time limit in seconds (ie max-age=3600 means that if the
                document is older than 1 hour a fresh copy will be fetched).
            -->
            <Set name="cacheControl">max-age=3600,public</Set>
        </New>
    </Set>
</Configure>

配置context.xml
/上下文
//server上的/path/to/files/
真的
最大年龄=3600岁,公共

我希望这能帮助别人

不知道如何使用Jetty,但在Tomcat中,您只需将一个新的
添加到
server.xml

<Context docBase="/opt/files" path="/files" />
现在还需要将其转换为
jetty.xml
flavor。基于web上的文档和示例,我有点猜测,所以不要把我牵扯进去:

<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容器外部目录的方法。我知道这可能不是最佳做法,但这适用于与internet隔离且只能从intranet中访问的服务器。根目录中的快捷方式(UNIX软链接或windows快捷方式)可能有效,但windows快捷方式无效(我刚刚测试过)。我想我已经找到了我自己问题的答案(在谷歌搜索之后)。请看下面我的答案。谢谢,这绝对是在Tomcat上实现的方法(我更熟悉Tomcat)。我认为对应的jetty文件名为jetty.xml。jetty上用于映射目录的xml语言似乎与tomcat有很大不同。感谢您的更新。不幸的是,我使用的是EclipseJettyAPI,这有点不同。第一个建议根本不起作用,第二个建议不起作用,因为eclipse jetty中没有“addHandler”方法。这个文件服务器示例有帮助吗?是的,如果下载jetty的副本,etc/jetty-fileserver.xml文件将包含该文件的副本。谢谢你的帮助!
<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>