Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify negative path match for servlet mapping

Is there a way to specify negative mappings in web.xml? For example, I want to set a filter for ALL requests EXCEPT those matching '/public/*'.

like image 945
Jack Dorsey Avatar asked Dec 13 '11 21:12

Jack Dorsey


1 Answers

No, that's not possible. You'd have to do the URL pattern matching yourself inside the doFilter() method. Map the filter on /* and do the following job:

HttpServletRequest req = (HttpServletRequest) request;

if (req.getRequestURI().startsWith("/public/")) {
    chain.doFilter(request, response);
    return;
}

// ...

or when there's actually a context path:

HttpServletRequest req = (HttpServletRequest) request;

if (req.getRequestURI().startsWith(req.getContextPath() + "/public/")) {
    chain.doFilter(request, response);
    return;
}

// ...
like image 189
BalusC Avatar answered Nov 22 '22 04:11

BalusC