Web frameworks and ugly URL’s

I’m starting a WebWork2 application, and it’s going okay, but I’m not happy at all with the URL’s that WebWork (at least, in its default configuration) requires.

I’m using a combination of actions and JSP. Generally, a form submits to an action, which may print something itself (using webwork dispatching) or redirect to a new JSP or action. And so far, the URL’s are very ugly. Some of you might not realize what I mean by ugly URL’s, so I’ve collected a few to show you.

Some ugly URL’s from around the internet:

For those of you who don’t agree that those are “bad URL’s” you might want to read the W3C essay Cool URI’s Don’t Change over and over until you agree.

Anyway, WebWork2 seems to force you to use their URL’s, which must end with .jsp and .action (if you’re using JSP and WW2 actions, of course). This is an implementation detail, of course, which language or framework was used to make the site, and I don’t want these implementation details shown to the whole world, making hard-to-remember URL’s which won’t be around if I switch from JSP to Velocity templates, or from WW to Struts.

So, I’m looking for a library or interceptor or servlet or filter or anything that will let me specify what my URL’s are, and which actual physical URL’s they correspond to. I’d like to have a file in my WEB-INF/ that looked like this:

<app-urls>
  <folder name="admin">
    <url path="new-calendar" action="jsp">newCalendar.jsp</url>
    <url path="new-calendar-submit" action="ww2-action">editCalendar</url>
    <url path="edit-calendar" action="jsp">editCalendar.jsp</url>
    <url path="edit-calendar-submit" action="ww2-action">editCalendar</url>
    <folder-root action="page">admin-index.html</folder>
  </folder>
  <url path="calendars" action="ww2-action">calendarList</url>
  <url path="some-old-url.php" action="redirect">calendars</url>
  <folder-root action="ww2-action">frontPage</folder>
</app-urls>

And these would be the only URL’s that existed on the server for this webapp. So, when someone goes to http://site.com/whateverapp/calendars, the calendarList WebWork2 action will be called. When someone goes to http://site.com/whateverapp/admin/, he or she will be shown the contents of admin-index.html.

If the user tried to go to http://site.com/whateverapp/admin/admin-index.html, however, the user would see a 404 not found.

With a scheme like this, a web application would act more like a Java object, the application, which implements an interface, specified by the URL configuration file. I think it would lead to more reliable results from search engines, more memorable URL’s, and

I don’t have much experience with servlets or Java web servers, so if any of you reading this have ever seen something like this, or if you have any ideas about how it could be implemented, please let me know. Maybe if nothing like this exists, I will write it.

9 Responses to “Web frameworks and ugly URL’s”

  1. Matt Raible Says:

    You could use the UrlRewriteFilter for pretty URLs. As for ending in .action, that’s up to you - I use .html for Struts, Spring and WW apps.

  2. Geert Bevin Says:

    One of the fundamental ideas behind the RIFE framework (https://rife.dev.java.net) is that we think that URLs should be fully in your hands and completely customizable. They should be like a seperate controller in the MVC philosophy, totally independent from the real underlying of your application. Therefore, the application should not be dependent on the URLs internally (to link between pages and such). If you decide to change the URLs, it should automatically be reflected throughout the whole application. You can then even go one step further and localize URLs to make them meaningful in other languages.

  3. Patrick Lightbody Says:

    Those URLs occur if you are using the standard ServletDispatcher. Not widely known, but there is another dispatcher included with WebWork that lets you do the kind of URLs you’re looking for. I think the name, unfortunately, is CoolUriDispatcher… or something equally geeky.

  4. Tony Says:

    Apache Cocoon allows you to totally separate your URI space from your actual resources. Absurdly useful.

  5. Charlie Hayes Says:

    You link to a page that says dont use titles in the URI yet the link to this article contains the subject. =)

  6. Keith Lea Says:

    The W3C article says URL’s like “http://www.w3.org/1998/12/01/chairs” are okay, which is exactly what my URL’s look like. They say that for example “1998/pics” is okay because the subject is followed by a date, so the user might understand that that page is what “pics” meant in 1998. Similarly, I think my weblog’s URL’s are very clear and do not violate anything recommended in that article.

  7. payday loans Says:

    1527 Sorry for the misrep understanfindg;

  8. online casino Says:

    Hello, a really interesting experience to visit your website. For sure i will come back soon. greets to all !

  9. mortgage Says:

    mortgage
    Please check the sites in the field of auto loan cash loan college loan

Leave a Reply