I have written something like this pretty easily in C# (string GetUrl(new { controller = "foo", action = "bar", baz = "fnord" }), based on the existing capabilities of the XmlRouteCollection class provided by the ASP.NET MVC framework (why it isn't there out of the box is beyond me; the additional required code was trivial). I am now faced with a JSP project, and I need the same ability: centralize the logic for generating all URLs in one place, based on a list of routing rules. Is there some code somewhere I could reuse/adapt to do this in Java? It seems like a common enough requirement, but google proved surprisingly unhelpful in finding something like this.
views:
88answers:
2I'm forced to use a particular framework so using something like grails or play won't work :-( I guess I'll have to implement it myself...
                  Oren Ben-Kiki
                   2010-02-22 21:45:53
                oh, it's really hard to implement, i'd tried some times ago :(
                  splix
                   2010-02-22 22:01:21
                Hard doesn't mean impossible right? =D
                  jpartogi
                   2010-06-16 07:15:21
                
                
                A: 
                
                
              JSP is just a Java based view technology, it is not a MVC framework, you can best compare JSP with "Classic ASP". The Java EE counterpart of ASP.NET-MVC is JSF (JavaServer Faces). I know JSF thoroughly, but I don't seem to recognize the part what you need. It seems more to be RESTFul-flavored. In that case, have a look to Spring 3.0 MVC. It provides "URI-template" annotations to listen on certain RESTFul requests. True, this is also not really what you're looking for, but it might give you some new insights and ideas.
                  BalusC
                   2010-02-22 22:14:06
                
              Spring URI templates are almost exactly what I need, except that they work in the wrong direction. They parse a URL and match it with an action; I need to specify an action and generate a URL. At any rate, this is academic; I can't use Spring, I'm stuck with a commercial framework (that has many other things, but not this).
                  Oren Ben-Kiki
                   2010-02-23 00:06:02