FreeMarker vs. JSP 2
I've been doing quite a bit of prototyping with Spring MVC and Struts 2 with both JSP and FreeMarker in the last few months. I'm trying to migrate a proprietary servlet-based framework with a proprietary JSP compiler to something that's open source. There's a couple of important features that the proprietary view framework has:
- It's expression language allows methods to be called with arguments.
- Templates can be loaded from a JAR on a remote server.
- XML in variables is escaped by default.
For #1, I've found this to be impossible with JSP EL or JSTL.
I've created JSP functions that allow argument passing, but they don't
allow overloading of functions. FreeMarker solves #1.
For #2, JSPs again fail because the templates have to be on the file system or in a WAR. FreeMarker solves this problem as well.
For #3, neither JSP or FreeMarker solve this problem. I realize
it can be fixed in FreeMarker by hacking the code - I've done the same
with Tomcat and solved it for JSP as well.
So based on the requirements in this project, FreeMarker is the clear winner. Here's some problems that I see with using it:
- No XML escaping of expressions by default
- No compile-time checking of expressions
- IDE support is limited to Eclipse (meaning very little in the way of code-completion)
Matt Raible has been building web applications for most of his adult life. He started tinkering with the web before Netscape 1.0 was even released. For the last 11 years, Matt has helped companies adopt open source technologies (Spring, Hibernate, Apache, Struts, Tapestry, Grails) and use them effectively. Matt has been a speaker at many conferences worldwide, including ApacheCon, JavaZone, Colorado Software Summit, No Fluff Just Stuff, and a host of others.
Matt is a DZone MVB and is not an employee of DZone and has posted 45 posts at DZone. You can read more from them at their website.
- Login or register to post comments
- 1635 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Rick Ross replied on Thu, 2008/01/17 - 2:46pm
Geertjan Wielenga replied on Thu, 2008/01/17 - 2:55pm