I need to serve my main application with the url pattern "/*"
so this pattern is matched to a Servlet.
The problem I am having is now all the css files and images located at "/css/all.css", "/images/" etc are going through this Servlet which is undesirable. I want these files to be directly accessed.
What is the better way to handle this situation?
Note: I am using Guice's Servlet Module to configure the patterns.
Thanks!
Modify doFilter() in order to check if the requested URL belongs to the list of predefined excluded URLs, if so then just forward the request to the next filter or servlet in the chain, otherwise do your authentication logic.
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.
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.
We need to know specifically which requests should be routed to your servlet, so that we know how to code the rules. I can't tell whether a) all requests except CSS and images should be sent to your servlet, or b) your servlet should only handle requests to a specific set of folders/directories. You will probably want to do one of two things:
Exclude specific folders:
^/(?!css|images).*
Or include specific folders:
^/myservlet/.*
You should change those *
symbols to +
if, as you indicated in your earlier question, you want to require at least one character after the /
in the pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With