In this article we'll begin by taking a look at servlets and JavaServer Pages, then proceed to learn about the MVC design pattern. After examining the problems these technologies solved, we'll focus on the Tapestry framework, study its advantages, and dispel some prejudices about it. This is the first article in a multi-part series covering Tapestry.
A servlet is basically a piece of Java code written in such a way that it can run on a server on the Internet. Servlets live in a so-called servlet container that handles all the low level issues, allowing the servlet author to concentrate on what exactly he or she wants to do.
Servlets are a foundation of every Java Web framework. Struts, JSF, Tapestry - all of them have at least one servlet, at the very least as a gateway between the world of Java and the world of Web.
However, in the early days of Java Web development there were no frameworks, only servlets. And if a developer wanted to display a dynamically created HTML page, he or she would have to print out HTML inside of Java code like this:
Now imagine that your page is a decent size, say, a hundred lines of code. You will have to write a hundred statements like this one. You can easily forget to escape one of those quotation marks or make some other error so that the servlet will not compile. This means the code is very fragile.
But say you managed to do everything properly and your servlet compiles and works just fine. Now your designer decides to change something on the page. Being a true Java programmer you might have no idea about HTML and styles, and your designer certainly has no idea about Java. So who will make the change? This means the code is difficult to maintain. Also, any minor change in the page contents or design will require recompilation of the servlet.
Although the servlets are powerful and efficient, they are not that good when it comes to rendering a dynamic HTML page. Some other solution was needed.