Java Servlets

properly encapsulated

The Perfect Servlet for Model-2 Architecture.

picture of the braches of a tree
As a company we believe in the flexibility and extendibility of delivering business applications through browser technologies. Because of this we use the MVC design pattern, translated in our architecture as JavaServer Pages Model-2 Architecture to model our code. We have researched extensively both MVC and its implementation, JSP model-2 Architecture, but have yet to find what we would consider a simple, robust and easily maintainable paradigm of the servlet in terms of the encapsulated Controller. Having spent a great deal of time developing our own strategy, we believe we have developed a simple and elegant solution to this MVC problem which we call the ‘perfect servlet’.

the request - response cycle

How it should work.

photo of a server system
When a user makes a request, in java terms an HttpServletRequest and HttpServletResponse are created and sent to an address in the container. The container selects the servlet based on information held in web.xml (the servlet mapping). Ultimately, both request and response will be forwarded to a device (a Java Server Page or "jsp") that will create a suitable page for "Viewing" on the user's browser.
The servlet is responsible for deciding what action to take, interacting with the software (the business "Model"), loading the HttpServletRequest with additional data and then deciding which jsp should create the xhtml to provide as the response. The servlet "Controls" the system.
Find out more about MVC here.

up for discussion

The Servlet Controller.

picture of cogs that are starting to wear
OK, but how should the servlet be laid out? It needs to interpret commands provided by the user and then take the appropriate action. We've seen many examples of the way to do this, but many seem overly complicated and we like simple and elegant!
So we've come up with our own solution. We like it because it does the job while being simple to write, understand and maintain. We'd like your views on our version of the "perfect servlet" so we've created a mini web application to demonstrate how it works and you can download the source code for inspection.
We'd be grateful for any comments and suggestions you might have