Could you discuss some guidelines to determine when it is best to use JSP vs. XML/HTML from a performance point of view, and some of the pitfalls?

Marcel Offermans

We have used both JSP and XSLT in a project to generate pages that display content from a database in (X)HTML form. In short, we found JSP to be quicker.

In both cases, we use a custom designed "object layer" on top of the database which allows us to talk to collections of objects instead of rows in a resultset.

The XSLT solution first adds a layer that implements DOM directly on top of the "object layer". This DOM was created lazily, so only parts that were actually used by an XSL template were created. The XSLT was then called from a servlet to generate XHTML.

The JSP solution directly works with the "object layer". It still contains some code in each page which could be removed by using a taglib but currently isn't.

The difference in speed is about a factor 2 to 3. In my opinion, this is caused by two things:

  1. The fact that an extra DOM layer is used, which creates more objects and therefore introduces more overhead.
  2. XSLT is an interpreted process (we don't compile XSL stylesheets into java code, that stuff is still experimental) where JSP is compiled.

I am the first person to agree that this is merely an example and that you cannot generalize these figures. They are very dependant on the chosen architecture, which I tried to describe in short.