将外部目录映射到web.xml [英] Map external directory to web.xml

查看:102
本文介绍了将外部目录映射到web.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there an easy way to map a directory in the web.xml or other deployment descriptor (jetty.xml, etc) files?

例如,如果我有目录/opt/files/,可以通过访问 http://localhost/some-mapping/?令我吃惊的是,应该有一些简单的方法可以做到这一点,但是我还无法找到方法(通过google,stackoverflow等).我发现的只是模仿文件服务器的servlet,这不是我想要的.

For example, if I have a directory /opt/files/ is there a way that I can access its files and sub-directories by visiting http://localhost/some-mapping/? It strikes me that there should be some simple way of doing this, but I haven't been able to find out how (via google, stackoverflow, etc). All I've found are servlets that mimic fileservers, which is not what I would like.

作为参考,我在AIX盒子上使用码头.

For reference I am using jetty on an AIX box.

推荐答案

不知道如何用Jetty做到这一点,但是在Tomcat中,您只需向server.xml添加新的<Context>:

No idea how to do it with Jetty, but in Tomcat you can just add a new <Context> to server.xml:

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

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

This way it's accessible by http://example.com/files/.... See if something similar exist for Jetty.

更新:在谷歌搜索后,普通Java代码"等效项如下:

Update: after Googling, the "normal Java code" equivalent would be something like:

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

现在尚未将其转换为jetty.xml风格.基于网络上的文档和示例,我有点猜测,所以请不要将我钉在上面:

Now yet to translate that into jetty.xml flavor. I am a bit guessing based on the documentation and examples found on the web, so don't pin me on it:

<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.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆