Fauxjsp
JSP implementation with fast page reloads that uses an interpreter rather than a compiler
Install / Use
/learn @ggeorgovassilis/FauxjspREADME
<img src="https://travis-ci.org/ggeorgovassilis/fauxjsp.svg"/> <img src="https://coveralls.io/repos/github/ggeorgovassilis/fauxjsp/badge.svg?branch=master"/> 
fauxjsp
fauxjsp is a Java Server Pages (JSP) implementation for use during development: JSPs are interpreted lazily (instead of compiled) which reduces application and page startup times, speeds up page reloads when JSPs change and doesn't require server restarts. Best used when developing, can be used in production also if specification compliance isn't critical.
TL;DR
web.xml:
<servlet>
<servlet-name>FauxJsp</servlet-name>
<servlet-class>fauxjsp.servlet.JspServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FauxJsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
Versions below (and including) 1.2.3 are in maven central:
pom.xml:
<dependency>
<groupId>com.github.ggeorgovassilis</groupId>
<artifactId>fauxjsp</artifactId>
<version>1.2.3</version>
</dependency>
Versions after 1.2.3 require a repository:
<repositories>
<repository>
<id>fauxjsp-repo</id>
<url>https://github.com/ggeorgovassilis/fauxjsp/raw/gh-pages/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
Change log
1.2.7-SNAPSHOT (not released on maven central)
- improved scriptlet execution performance
1.2.3
- less aggressive HTML escaping (don't escape high-end unicode characters)
1.2.2
- performance test extends to scriptlets, minor refactoring
1.2.1
- fixed bug in resolving classpath includes
1.2.0
- permanently caching parsed JSP and tagfiles in "production" mode
1.1.0
- simplified EL expression handling, improved rendering performance
1.0.0
- handling
trimDirectiveWhiteSpaces,c:setbody content implemented
0.0.9
- released to maven central, otherwise identical to 0.0.5-SNAPSHOT
0.0.5-SNAPSHOT
- implemented <%@page %> directive for content type and character encoding
- ability to handle tagfiles and JSPs in classpath locations
- updated dependencies servlet-api 4.0.1, tomcat 9.0.8
- handling Unicode in response
- fixed bug in foreach handling
- fixed bug in xml namespace parsing
- housekeeping
0.0.4-SNAPSHOT
- Implemented JSP comments
- populating context and session attributes as JSP variables
- added sessionScope, contextScope, requestScope implicit objects
- added empty applicationScope implicit object
- able to iterate over arrays
Another JSP implementation?
Yes. In short:
- a. there aren't that many (I only know of two, Oracle JSP and Jasper)
- b. faster page reload than other implementations because it interprets JSP rather than compiling it to byte code
- c. no memory leaks, more robust, more precise and helpful error messages for syntax- and runtime errors
- d. extensible
- e. if compliance and performance are not a top priority, it comes with a few neat features not available with standard JSP such as loading tagfiles and JSPs from the classpath.
For most of you cool dudes JSP is horribly out of fashion, but I like using it for prototyping and tagfiles. Sadly and surprisingly, not many people know about tagfiles despite them being a well-supported and mature technique for creating reusable web UI components.
Starting a JSP-heavy application is slow because other JSP implementations will first compile JSP and tagfiles to java source code, then to byte code and then to machine code. Also, when making changes to JSP files, the entire process has to be repeated which slows down development. At some point you'll even get unexplainable compile errors, class loading errors, run out of memory and the likes, you'll know you've had enough and you'll restart the servlet container.
fauxjsp implements a JSP interpreter and a JSP servlet which reads JSP files and interprets them on the fly, skipping compilation altogether. This brings the benefit of instant page reloads, fast application start times and robustness (no classloader fiddling!) but, obviously, the generated JSP pages are slower under load than the standard implementation which may be an issue in production.
Currently implemented features:
- Renders JSP pages
- Renders tagfiles
- Supports most core JSTL taglibs
- Supports scriptlets
- Is modular and extensible
- Supports an idiomatic way of loading tagfiles and JSPs from the classpath
Constraints and missing features:
- Out-of-the-box only core taglibs are supported. This means that core taglibs like
c:outwill work but third party taglibs such as displaytag won't, unless you re-implement them for fauxjsp. - Not all core taglibs are supported and not all features of the supported ones are implemented which is not an intentional omission. Please submit a bug report if you think something is missing.
- I didn't read up on JSP/JSTL/servlet specifications, the implementation is empirical (aka "works for me").
- Servlet containers needs to provide some EL 3.0 implementation (i.e. works with Tomcat 8, not with Tomcat 7)
- I didn't read up on variable scoping; scopes work similarly to variable scopes in Java blocks.
- Encoding is pinned to UTF-8.
- Not all JSP implicit objects are available.
- Newline handling in output may differ from standard JSP implementations.
- Scriptlets are implemented via beanshell which means that there might be deviations from how scriptlets are handled in Jasper et al.
- The JSP language ecosystem is rather complex; HTML, JSTL, EL and scriptlets are frequently mixed in the same file which is hard to parse. fauxjsp uses a very simple parser which means that it's likely to get confused by characters in EL expressions which have special meaning in XML, e.g. "<" or ">" as strings in scriptlets, "{" or "}" as strings in EL - you might have to use named entities. Note that release 0.0.4 significantly improved handling of such characters.
- Does not support web fragments
- Uses a
classpath:prefix for resolving tagfiles and JSPs in the classpath. Does not support the standard way of resolving classpath resources.
With all these restrictions, why should you bother?
Because:
- JSPs and tagfiles reload instantly saving you plenty of time and server restarts.
- fauxjsp implements a subset of the JSP specification; if it works in fauxjsp, it will probably work in Jasper, too.
- it's tested on large and complex pages and the important things seem to work
Bonus:
- If you're willing to abandon the standard JSP implementation, then fauxjsp comes with a few neat extra features and simplifications not available in standard JSP
Getting started
- add the dependency to your project
<dependency>
<groupId>com.github.ggeorgovassilis</groupId>
<artifactId>fauxjsp</artifactId>
<version>1.1.0</version>
</dependency>
OR
download sources and compile
git clone https://github.com/ggeorgovassilis/fauxjsp.git
cd fauxjsp
mvn install
- Declare an instance of the JspServlet in web.xml:
<servlet>
<servlet-name>FauxJsp</servlet-name>
<servlet-class>fauxjsp.servlet.JspServlet</servlet-class>
<!-- optionally specify a root for resource lookup, defaults to "/"
<init-param>
<param-name>base-path</param-name>
<param-value>/WEB-INF/jsp/</param-value>
</init-param>
-->
</servlet>
<servlet-mapping>
<servlet-name>FauxJsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
Run-time Dependencies
- JSP API 2.0
- Java EL 3.0 API
- JSTL 1.2
- Servlet API 4.0
- commons-lang 2.6
- beanshell 2.0b5
- log4j 4
Servlet API, JSTL, EL are scoped as provided because the servlet container or the web application contribute these dependencies
log4j, Beanshell are scoped as provided because they are optional
commons-lang is scoped as compile because it's mandatory
For up-to-date details, please see the pom.
Extending fauxjsp's functionality and working around bugs
Please submit a bug report when you find a bug or require a feature implemented. Now, in real (project) life, you are probably on a tight schedule and don't want to wait for an official fix. fauxjsp is modular and easily extensible. So have a look at the next chapter about fauxjsp's architecture which will help you understand the various, rather simple components, how to modify them and implement new functionality.
Architecture overview
JspServlet
JspServlet accepts an HTTP request and renders the requested JSP. The entire sequence looks like this:
- Gets the requested JSP file's name from the
ServletRequest - Looks at
jspbase(see javadocs forJspServlet) for the JSP file - Asks the
JspParserFactoryfor a newJspParser - Gives the JSP file to the
JspParserwho parses it, recursively resolves dependencies and returns aJspPage - Creates a new
RenderSession - Asks the
JspRendererFactoryfor a newJspRenderer - Gives the
JspPageandRenderSessionto theJspRendererwho renders it - Streams the results to the browser
JspServlet has a bunch of protected methods which construct the various factories mentioned earlier. Shoul
Related Skills
node-connect
336.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
336.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.0kCommit, push, and open a PR
