包装默认servlet但覆盖默认的webapp路径 [英] Wrap the default servlet but override the default webapp path

查看:91
本文介绍了包装默认servlet但覆盖默认的webapp路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态html,imgs,flash内容的文件夹,它们位于webapp文件夹之外。现在我正在使用符号链接将该文件夹映射到我的webapp目录。我遇到的问题是,当我取消部署我的应用程序时,它遵循符号链接并删除所有这些文件。

I have a folder of static html,imgs,flash content that lives outside of the webapp folder. Right now I'm using a symbolic link to map that folder into my webapp directory. The problem i have is when I undeploy my application it follows the symbolic link and deletes all these files.

我试图实现的一个解决方案是一个特殊的servlet包装默认servlet但使用不同的相对路径。我无法找到如何以覆盖默认servlet路径的方式包装默认servlet。

One of the solutions I'm trying to implement is a special servlet that wraps the default servlet but uses a different relative path. I'm having trouble finding out how to wrap the default servlet in a way that overrides the default servlet path.

以下是我正在使用的内容:

Here is what I'm working with:

public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
    throws ServletException, IOException {
    final RequestDispatcher rd = getServletContext().getNamedDispatcher("default");
    final HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {

        @Override
        public String getServletPath() {
            return "/usr/depot/repository";
        }
    };

    rd.forward(wrapped, resp);
}


推荐答案

你可以写自己的servlet用于提供静态内容(这并不难)或尝试扩展而不是包装DefaultServlet。无论哪种方式,您生成的servlet都将在 web.xml 中配置为默认值(使用default作为servlet-name)。

You can either write your own servlet to serve static content (which is not that hard) or try to extend rather than wrap the DefaultServlet. Either way, your resulting servlet will have be configured in place of default in your web.xml (using "default" as servlet-name).

也就是说,DefaultServlet只会在你的webapp上下文中提供静态内容;为了改变你必须创建/绑定到JNDI你自己的ProxyDirContext实例指向外部文件夹,我不知道这是否会起作用;它的配置过程非常复杂。

That said, DefaultServlet will only serve static content from under your webapp context; in order to change that you'll have to create / bind to JNDI your own ProxyDirContext instance pointing to the outside folder and I'm not sure whether that will work; its configuration process is rather involved.

试图覆盖servlet路径不会让你到任何地方。

Trying to override servlet path will not get you anywhere.

这篇关于包装默认servlet但覆盖默认的webapp路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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