Important note: This post is not being updated. For up-to-date information refer to the project repository: https://github.com/ggeorgovassilis/fauxjsp/
In this post I’ll present a new open source project I’m currently working on, fauxjsp
 which re-implements JSP in a way that is more robust and faster for developers. It is intended for development, where it indeed is fast and leightweight compared to the standard implementation.
Java Server Pages
(JSP)  is a stable, widely supported scripting technology for creating dynamic HTML pages which went out of fashion for various reasons: JSF, Web 2.0, yet I speculate that it would be more popular if people knew about tagfiles
 which allow authoring of reusable components by writing JSP. Especially in modern Web 2.0 applications, JSP allows for very easy templating and UI construction while allowing at the same time dynamic configuration via MVC applications.
Developing JSP is slow
As far as I know, Tomcat’s Jasper
 is the only JSP implementation – at least the only I ever worked with. Applications deployed into Tomcat receive Jasper automatically as a servlet named “jsp” to which all JSP pages are mapped. When a JSP page is requested (either directly by the browser or forwarded to by an MVC framework), Jasper:
- picks up the JSP file
- resolves any included code fragments, tagfiles and taglibraries
- generates Java source code
- compiles the Java source code to byte code
- loads the byte code
- renders the page by running the loaded code
In a production environment, highly optimized Java code resulting out of these steps renders web content fast and efficiently. However, during development every time a file is changed, Jasper will pull the changed files through these steps again, possibly repeating the ordeal for JSP dependencies. This becomes especially slow when the servlet container is restarted, which means that the JVM hasn’t “warmed” up Jasper yet.
A further problem arises from implementation glitches in the entire JSP-JSTL-Jasper-Tomcat chain which lead sooner or later during the development process to inexplainable compile errors, ClassNotFoundErrors, OutOfMemoryErrors, class loading frenzies and servlet container instabilities.
Speeding up JSP loading
 is an open source JSP parser and renderer which simply interprets JSP and renders it on the spot, without going through Jasper’s compilation steps. While this obviously speeds up loading and rendering frequently changing JSPs, it is not suitable for production
as every access to the page will parse it again, leading to slow response times and high CPU utilization.
Using it is quite straight forward:
- Check out the repository and build it
- Include dependencies into your web application
- Include the fauxjsp declaration in your web application’s web.xml:
There are several, more or less important deviations from Jasper’s implementation:
Taglibs are not supported directly. While discovering taglibs is a task of manageable complexity, rendering them is difficult because of the complex and implicit JSTL API. A few core taglibs have been directly hard-coded into the parser and more will probably follow. However using third-party taglibs in a JSP page will require custom development.
The parser is not as robust as Jasper: sneaky characters like “, in tag attributes can confuse the parser and thus their escaped forms &, < and > must be used where possible.
Scriptlets won’t work since that would require a slow source code compilation.