javaregexguicedeployment-descriptor

How to exclude/redirect certain url pattern in web.xml or Guice servlet module?


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!


Solution

  • 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.