Archive
Unicode Web Apps
Are you trying to support foreign languages in your web application and find ?? instead of 你好? Do your users get a bunch of funny vowels (Ãă) when they attempt to past “smart” quotes in your content management system (a problem I termed Irritable Vowel Syndrome)? The problem is broken Unicode support somewhere in your stack.
With the prevalence and long history of Unicode, one might be surprised that it is still not trivial to create a web application that supports unicode! Let me show you how.
FreeMarker, JSP Taglibs outside WAR
Whether you are trying to integration test your controllers from within an IDE or using FreeMarker to generate content outside of a WAR, getting access to your JSP tag libraries can be difficult. You are probably faced with an error such as ‘JspTaglibs["..."] is undefined’. FreeMarker is kind of hard-headed about JSP tag libraries. Let me show you how to get around it.
Update (Sep 6, 2011): I believe this issue has been resolved (here and here) in FreeMarker 2.3.18. If you have a chance to test it, please comment on your success.
Spring, SiteMesh, and FreeMarker
Both Spring and SiteMesh have built-in support for FreeMarker. However, combining the three technologies without duplicating configuration can seem nearly impossible on the surface. In fact, one can easily find several attempts on the Internet. Fortunately, things have improved dramatically in recent years and with a little understanding of how SiteMesh works, we can achieve bliss with very little work.
Spring MVC: Integration Testing Controllers
One of the greatest benefits of Spring MVC is that it removes your dependency on a servlet container. In theory, you should be able to test your controllers, and your entire web stack, from a testing harness like JUnit. In reality, you become just as dependent on the wonderful services offered by DispatcherServlet and a complete WebApplicationContext (request parameter binding, validation, model attributes, request mappings, and aspects such as Spring Security). In this article, I will show you how to create a mock servlet context and WebApplicationContext from within JUnit.