Html template system using java annotations

Peter Speck

Studenteropgave: Semesterprojekt


The problems that motivate this project are to (1) solve the lack of separation between html templates and java code when using existing template systems (e.g. embedded language or macros), to (2) solve the lack of scoped declaration of macros and java variables inside template loops, and (3) to solve the lack of validation of template macro definitions at compile time to help finding bugs before the web applications are deployed. Annotations are used as metadata format for specification of the dynamic parts of the html template and 74 annotations are designed for the template system. The html templates don't contain embedded macros and are fully valid html files without any special tags or attributes, and well suited for editing in visual editors. An annotation-based template compiler and runtime are implemented and tested. Strict type checking is performed by the template compiler when it processes the annotations. The compiler generates java source files which enables IDEs to show usages of template macro implementations, i.e. servlet methods and fields. The system provides template looping constructs by using Iterators and automatically instantiating the appropriate inner class for each object returned by the iterator. The inner classes provide scoping for temporary variables used by the loops to avoid polluting the global servlet scope with temporary variables. Tests of annotations as specification format show that the new system provides very concise specifications for common web implementation design patterns and makes servlets easier to maintain.

UddannelserDatalogi, (Bachelor/kandidatuddannelse) Bachelor el. kandidat
Udgivelsesdato18 jun. 2007
VejledereBo Holst-Christensen


  • java
  • templates
  • annotations
  • html