tags:

views:

102

answers:

4

From what I know of MVC outside of the Java world (PHP and Ruby on Rails), all requests are first sent to the front controller (or dispatcher... or boostrap, etc.), and the front controller looks to the request path pattern in the URL in order to determine what class/method should handle the request. In Java MVC, it appears that servlets are mapped with the url pattern in the deployment descriptor (web.xml), but the file extension and url pattern doesn't appear to be very flexible. Are there any Java MVC frameworks that use a front controller to read the request path exclusively to determine what classes should execute? Would it be fairly easy to hack Spring MVC to do this? Any examples? Thanks!

A: 

Java servlet mappings can also be by file extension.

Much like many non-Java frameworks, you could map all requests to a single servlet that then processes them but that tends to be discouraged in Java. It's certainly possible though.

If you want more REST-style URLs where you declare the mapping of path elements, you might want to look at the Spring MVC setup in Spring 3.0.

cletus
A: 

I agree the URL mapping is not very flexible but you can handle mapping with URLRewriteFilter

http://tuckey.org/urlrewrite/

For this purpose, the filter works almost like a controller.

ZZ Coder
+1  A: 

An example of one tool that works as you desire is web4j.

By default, it maps incoming URLS to the Action class whose package-qualified name maps in a fairly natural way the the incoming URL.

Example from its docs:

This is an example of how that particular tool performs the task. Since this is such a basic feature of web apps, I would imagine that nearly all such tools have similar mechanisms.

I am not a big user of Spring, but I can see from its docs that it has a number of ways of mapping requests to Actions :

John O
A: 

Check out stripes: http://www.stripesframework.org/display/stripes/Quick+Start+Guide

I've been looking at it as a possible upgrade from struts. There is an example on that page that is very similar to the web4j example given by John O.

StevenWilkins