简体   繁体   中英

servlet filter not working over virtual directories in tomcat

I had configured virtual directories in glassfish3.x over which I could write filters.

For an example I could access files at c:/web from http://localhost/TestApp/web over which I could also place a filter at my web app's web/xml file with

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

Unfortunately Tomcat 8.0 is not allowing me to write a filter above that. It simply ignores the filters and shows the content in the web directory.

The problem is anybody can access all of the files in the "web" folder.

Any how can we place filter over the virtual directories.

FYI - i have made the web app named "TestApp" and the virtual config is located at "$tomcat_dir/conf/Catalina/localhost" directory with the file name "TestApp#web.xml" file and having the content

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

Regards

The context XML file TestApp#web.xml is mapping requests to /TestApp/web/... to the webapp. In the webapp, paths are relative to that, so /TestApp/web/x.txt is path /x.txt to the webapp, and will serve file C:/web/x.txt .

Change the filter to /* , so all requests are filtered, incl. the request for /x.txt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM