Home arrow Apache arrow Page 2 - Apache Tapestry 4 Tutorial

JavaServer Pages came to the rescue - Apache

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.

  1. Apache Tapestry 4 Tutorial
  2. JavaServer Pages came to the rescue
  3. The Holy Trinity of software development
  4. Why Tapestry?
  5. Tapestry and prejudices
By: Alexander Kolesnikov
Rating: starstarstarstarstar / 159
April 03, 2007

print this article



Technically, a JSP page is just the same servlet as it gets compiled into a servlet behind the scenes before it is shown to a Web application's user. However, from the developer's point of view, working with JSP pages is a completely different thing. You can have as much HTML in your page as needed, and if you want to use some Java code, you just insert a scriptlet, as in this example:

<p>Some nicely formatted HTML goes here</p>


   // And here is some Java code as needed by the page  

   String name = request.getParameter("firstName");


<p>Hello <%= name %></p>

This was the original design of JSP technology. What can be better: designers can work on their pieces of HTML, Java programmers can work on their pieces of code, and whatever is generated in the code can be easily inserted into HTML using a simple notation.

But this holds true only for simple pages with limited functionality. As the dynamic part of the page becomes more complex, Java unavoidably gets mixed with HTML. Have a look at another example:


 for (int i = 1; i <= metaData.getColumnCount(); i++) {

  if (metaData.getColumnType(i) == Types.DOUBLE) {


          <td align='right'>

              <%= formatter.format(resultSet.getDouble(i)) %>



  } else {



              <%= resultSet.getObject(i).toString() %>






If you write such a page yourself and you know both HTML and Java, no problem, you can do this. However, many Java Web applications are created by a group of people, often with narrow specializations, and this kind of Java/HTML cocktail makes both designers and developers unhappy.

As a result, it was decided that scriptlets are a bad thing, and they should not be used. Instead, a set of tags was provided. If designers don't like Java code, they should be much happier working with tags.

The idea was to have all Java code in some separate Java class, referred to as a bean, and then you can use that bean from your JSP page by using a few simple tags like these:

<jsp:useBean id="myBean" class="com.example.MyBean"/>

Hello <jsp:getProperty name="myBean" property="firstName"/>

Again, the idea wasn't bad, especially for simple pages. But for anything more complex the existing set of tags was severely limiting.

Of course, there was an opportunity to write your own custom tags and do in them everything you can imagine. But writing custom tags isn't for the fainthearted; one would need a pretty good understanding of the details of JSP technology to do that. Also, if you wanted to output some HTML in your custom tag, you would have to print it out in the same way as in a servlet.

Still, many developers produced numerous libraries of custom tags, and one such library, JSTL (JavaServer Pages Standard Tag Library), became a part of JSP standard.

However, obstinate developers kept using scriptlets in their JSP pages, saying that even the best custom tags do not give them the flexibility they require. This finally led to yet another addition to JSP - the Expression Language (EL).

Expression Language is truly powerful and convenient. The only problem is that to get rid of Java code inside of JSP pages, three different notations were introduced: standard tags, custom tags and EL expressions. All three have slightly different logic, naming scheme and rules, so that learning them in detail can be quite a nuisance! Have a look at this brief example, taken from real life code:


   <c:forEach var="column"   


          <th><c:out value="${column}"/></th>



Does this look like a clean separation between HTML and code? I wouldn't say so.

Still, JavaServer Pages technology solved the tasks for which it was created. However, this is a rather low level technology. Creating a Web application from scratch using JSP pages and servlets required writing a lot of "boiler plate code" again and again, or copying and pasting large chunks of code - what a reliable source of hard to find errors!

Some kind of framework was required that would have all the basic stuff already written and would provide some sort of architectural solution for a future Java Web application. A number of such frameworks appeared; the most famous of them is Apache Struts. Typically, they embodied the MVC (Model-View-Controller) pattern, widely regarded as a panacea for many problems of software development.

>>> More Apache Articles          >>> More By Alexander Kolesnikov

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: