What's the best way to define some values based on the URL?
Let's say for example I want all my URLs for servlets to take the form:
http://mysite.com/module/action?arguments
What's the most scalable way to handle mapping the values in place of "module" and "action"? For example, I might have a "forum" module and have an action to "deleteThread", called like so:
http://mysite.com/forum/deleteThread?id=321
I know I can just parse it myself, but is there a better way to handle this via some settings in web.xml or similar? All my requests go through a Front Controller which needs to know which module and action have been requested so that it can run the appropriate action controller.
Cheers,
Chris
[687 byte] By [
d11wtqa] at [2007-11-27 9:58:42]

# 1
At the risk of repeat-posting, I'll clarify. Say I create a file named routing.xml which defines some routes like this:
<routing-config>
<route>
<name>Standard rule</name>
<description>
This route maps the first two parts in the path with the module and action
</description>
<url-pattern>/:module/:action.do</url-pattern>
</route>
<route>
<name>Default Index</name>
<description>
Allows the module to be specified without the action for "Index" actions.
</description>
<url-pattern>/:module.do</url-pattern>
<request-parameters>
<parameter key="action" value="Index" />
</request-parameters>
</route>
<route>
<name>Homepage</name>
<description>
Loads the Home page
</description>
<url-pattern>/</url-pattern>
<request-parameters>
<parameter key="module" value="Home" />
<parameter key="action" value="Index" />
</request-parameters>
</route>
</routing-config>
The bits like ":module" which be represented by the actual name of the module in the URL. Does anyone know if something like this already exists? :)
I wrote this exact same thing in PHP5 just a few weeks ago but I really don't have the motivation to write it all over again in Java :P On a side-note, things like this usually come with helpers for turning unclean URIs into clean URIs.