Re: how to send data to a pre configured servlet
Dundonald wrote:
So if I use the splat ("*") you mean something like:
<servlet-mapping>
<servlet-name>CatchAllServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
?
And if I had such as the above can I still use all my other servlet
mappings?
As I understand it, yes. This is why I say to look stuff up, since
these details are easy to find. I don't deal with setting the
url-patterns myself usually, and I can't know everything that you might
want to do with your applications, so it's good for you to know how this
works so that you can plan.
Explicitly for <url-pattern> the matching goes like this (I think):
1. Any exact match without a wildcard is taken first. A pattern like
/hello_world would always match a path of <context>/hello_world.
2. Then the longest possible match is taken that ends in a wildcard. So
a pattern of /hello* would match <context>/hello_world before /h* would.
3. Then any matches that begin with a wildcard are taken. A url-pattern
of *.do would be matched last after all of the above patterns,
regardless of length. I don't know if there's a tie breaker for
extensions like there is for 2. above. I don't think so.
4. Finally, if nothing else matches, /* is matched if present. It's a
catch-all.
This is in O'Reilly's _Learning Java_ btw. But there are better books
for web apps. You should definitely get some kind of primmer or
reference, wildcard matching in <url-pattern> is pretty basic stuff.