【问题标题】:servlet filter not working over virtual directories in tomcatservlet过滤器无法处理tomcat中的虚拟目录
【发布时间】:2023-03-30 18:08:01
【问题描述】:

我在 glassfish3.x 中配置了可以编写过滤器的虚拟目录。

例如,我可以从 http://localhost/TestApp/web 访问 c:/web 上的文件,我还可以在我的 web 应用程序的 web/xml 文件中放置一个过滤器

<filter-mapping>
    <filter-name>dir_filter</filter-name>
    <url-pattern>/web/*</url-pattern>
</filter-mapping>

不幸的是,Tomcat 8.0 不允许我在此之上编写过滤器。它只是忽略过滤器并在 web 目录中显示内容。

问题是任何人都可以访问“web”文件夹中的所有文件。

我们如何在虚拟目录上放置过滤器。

仅供参考 - 我制作了名为“TestApp”的网络应用程序,虚拟配置位于“$tomcat_dir/conf/Catalina/localhost”目录,文件名为“TestApp#web.xml”文件,内容

<?xml version='1.0' encoding='utf-8'?> 
<Context docBase="C:/web" debug="0" privileged="true"></Context>

问候

【问题讨论】:

    标签: java tomcat glassfish servlet-filters tomcat8


    【解决方案1】:

    上下文 XML 文件 TestApp#web.xml 正在将请求映射到 /TestApp/web/... 到 web 应用程序。在 webapp 中,路径是相对的,所以 /TestApp/web/x.txt 是 webapp 的路径 /x.txt,并将提供文件 C:/web/x.txt

    将过滤器更改为/*,以便过滤所有请求,包括。 /x.txt 的请求。

    【讨论】:

    • nope 带有 /* 的过滤器无法监听虚拟目录请求。
    猜你喜欢
    • 2018-07-05
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2018-08-06
    • 2015-07-07
    相关资源
    最近更新 更多