Servlets and JSPs: Crooked Foundations

4 PM March 12, 2004

Charles says Struts and similar web frameworks should be thrown away. He writes:

Give a reasonably good OO developer the task of building a web framework, their first attempt will probably be something resembling Struts. which I suppose gives good support to the “Build one to throw away” theory.

Call me a l33t PHP programmer, but I don’t think Struts is the thing that needs throwing away. The problem runs deeper than that.

In the late 90s, Sun, fresh from their success with Applets, charged their Distinguished Engineers with defining a common standard for web frameworks. The Distinguished Engineers drew on the rush-to-market, look-at-us-we’ve-got-one-of-them-too mentality of the dot-com era, and gave us Servlets and JSPs.

The Servlet and JSP standard is a good first attempt. But, like all first attempts, it should have been thrown away once the world had learnt some lessons from it.

These are some of the lessons I learnt from Servlets and JSPs:

  • A web framework must address the whole HTTP standard, including the difficult bits. The framework should understand multi-part HTTP requests, and be able to produce multi-part HTTP responses.
  • A templating mechanism is not the same as a servlet. JSPPage should not extend Servlet. On a practical level, JSPs should not need to be registered in the server’s URL space, where the user’s browser can call them directly.
  • The Servlet authentication mechanism is unsuitable for many uses. A related defect is the lack of a simple, standard way for a web app to logout (or deauthenticate) a session.

The Servlets and JSP approach is so widely and thoroughly accepted by the Java community that it can’t be thrown away anytime soon. However, until it is thrown away, Java web frameworks will be building on crooked foundations.

By alang | # | Comments (9)
(Posted to javablogs, Software Development and Java)
© 2003-2006 Alan Green