Servlet Mapping with wildcards

D

Dale

Is there any way in the web.xml, to define the servlet mappings in
such a way that I want to map all urls, EXCEPT for particular
patterns.

Here is my problem.... I want to ensure that requests for CSS (*.css)
or JS (*.js) files don't submit a request to the server most of the
time (so the browser just uses its own cached version). Any other url
would hit a default filter or servlet, which would then delegate to
other appropriate servlets.

The only way I can think to do this would be to map all 3 and 2 letter
extensions that are not CSS or JS to this default filter. Is there no
NOT wildcard I can use or something?

Thanks,
Dale
 
W

Wendy S

Dale said:
Is there any way in the web.xml, to define the servlet mappings in
such a way that I want to map all urls, EXCEPT for particular
patterns.

I don't think so...

SRV.11.2 Specification of Mappings
In theWeb application deployment descriptor, the following syntax is used to
define
mappings:
.. A string beginning with a '/' character and ending with a '/*' suffix is
used
for path mapping.
.. A string beginning with a '*.' prefix is used as an extension mapping.
.. A string containing only the '/' character indicates the "default" servlet
of
the application. In this case the servlet path is the request URI minus the
context
path and the path info is null.
.. All other strings are used for exact matches only.
Here is my problem.... I want to ensure that requests for CSS (*.css)
or JS (*.js) files don't submit a request to the server most of the
time (so the browser just uses its own cached version). Any other url
would hit a default filter or servlet, which would then delegate to
other appropriate servlets.

I suppose you could just let everything hit the filter, check for .css & .js
at the top of your Filter and return immediately if it's one of those,
otherwise go ahead and do your processing. You could put the list of
"ignore these" extensions in a .properties file or a database and retrieve
it to avoid hard coding it in the Filter.

Is it that you don't know what extensions are valid for your app, or you
think there are too many of them to map?

(Removed comp.lang.java)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top