Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude url from filter-mapping in web.xml

I am using spring mvc and I need to exclude urls from filter-mapping. It means, I have static content like pictures and css and js ... and I need to not process these request, for example from security filter. I tried urlrewrite, but I was not able to redirect the urls directly to defaultServlet, which is defined in catalina web.xml. I need to jump over filters, because I have a lot of them. Is there a way? Thanks

EDIT - I thought maybe I could create filter which will if decided jump over other filters and execute the servlet at the end. Is it possible to do that? Thanks

like image 330
tomas.tunkl Avatar asked Sep 30 '11 07:09

tomas.tunkl


People also ask

How do I exclude a URL from filter mapping?

By default, filters doesn't support excluding a specific URL pattern, whenever you define a URL pattern for a filter then any request matching this pattern is handled by the filter without exceptions. The simplest way for excluding URLs from a filter is to map your filter to a very specific pattern.

How do you exclude a URL?

Exclude sites from your search engine:In the Basics tab, click Advanced under Sites to Search to expand the Sites to exclude section. Click Add under Sites to exclude. Enter the URL you want to exclude and select whether you want to include any pages that match or only that specific page.

What is URL pattern in filter mapping in Web xml?

The url-pattern element of a servlet-mapping or a filter-mapping associates a filter or servlet with a set of URLs. When a request arrives, the container uses a simple procedure for matching the URL in the request with a url-pattern in the web. xml file.


1 Answers

In the end I used:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>Warn</param-value>
    </init-param>
</filter>

and url rewrite was defined:

<urlrewrite default-match-type="wildcard">
<rule>
    <from>/static/**</from>
    <to>/static/$1</to>
</rule>

like image 69
tomas.tunkl Avatar answered Nov 11 '22 17:11

tomas.tunkl