Fancy Templates

So far our servlet has only sent plain text to the browser. Rather than writing HTML inline or using Java Server Pages—the common alternative to servlets in Java—we’ll introduce a simple templating library called FreeMarker.[13] Download the GAE-compatible binary FreeMarker .jar, and drag it into your project’s war/WEB-INF/lib directory. If the JAR doesn’t show up as a Referenced Libraries, click the project’s properties, select Java Build Path, and under Libraries choose Add JARs then drill down war/WEB-INF/lib, choosing the JAR.

We need to add a method to the LunchRouletteServlet that renders a template file with some given data, and write the result to the response stream. This function assumes the FreeMarker template generator ...

Get Programming Google Glass now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.