Is there a key difference between url-pattern / and /* ?
Chris Corbyn
Ranch Hand
Joined: Jan 14, 2007
Posts: 114
posted
0
There appears to be a subtle difference between:
and
Both seem to send all requests through the servlet I'm aming for, but the /* on messes up forwards to JSP files. My app works as I expect when I use the "/" version (I don't need suffixes or prefixes since I've written some routing code). I'm wondering if they are supposed to be behave differently or if my Tomcat container has a little bug I'm exploiting wrongly?
If you use the "/" version, would you expect a URL like this to map to it....
It's not a bug. In the second example, the "*" acts as a wild card to matches all URLs. In the servlet request, the extra parts of the URL are available as the so-called "path extra info".
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.
The pattern /* will force everything through your servlet. The pattern / will make your servlet the default servlet for the app, meaning it will pick up every pattern that doesn't have another exact match.
I just tested this in Tomcat and the / mapping will override a 404 error page entry in web.xml. [ August 19, 2007: Message edited by: Ben Souther ]
I've also just noticed that it overrides the welcome-file entry. Make sure that's what you want before you use it this way.
Chris Corbyn
Ranch Hand
Joined: Jan 14, 2007
Posts: 114
posted
0
The routing would handle that too:
Effectively you could say that all I've done is made a more flexible <servlet-mapping> configuration. It's not finished yet though because mapping request URIs to values is only one side of it. It also need to be able to take an unclean URL and produce the clean version of it:
Chris Corbyn
Ranch Hand
Joined: Jan 14, 2007
Posts: 114
posted
0
OK, this is working great. I'm posting mostly out of interest since nobody understood me the first time I explained how I wanted to carry this idea from a PHP framework point of view
Everything to do with URLs and link production (not yet developed) is centered around a "Router" class and an XML file which provides everything it knows about what a URL looks like.
I wont post the code for the Router class yet, but just to explain:
My front controller delegates requests over to action controllers. Each "action" belongs to a "module" which is effectively a collection of actions in the same sub-package.
e.g. app.somemodule.SomeAction, app.somemodule.AnotherAction, app.anothermodule.IndexAction etc.
The only way the Front controller knows which action to run is from the URL. Ok, nothing new here, this would work fine.
Now one day we decide to change the "forum" module to "bbs" but only in terms of the URL, no point in rewriting a whole load of code to change all the hyperlinks right?
I can't be bothered to go on any more, but basically that's what I've been doing and what I was talking about a few weeks ago when I first mentioned this and got a slightly confused response
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Is there a key difference between url-pattern / and /* ?