This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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....
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.
Joined: Jan 14, 2007
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:
Joined: Jan 14, 2007
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.