/** * Created using IntelliJ IDEA. * Date: Mar 29, 2007 * Time: 7:49:31 PM * User: Rob Dawson robert@rojotek.com */ package rojotek.freemarker; import freemarker.template.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; /** * @author Rob Dawson robert@rojotek.com */ public class ControllerServlet extends HttpServlet { private Configuration configuration; public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); configuration = new Configuration(); configuration.setClassForTemplateLoading(this.getClass(), "templates"); } protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Template template = configuration.getTemplate("start.html"); Map freeMarkerData = new HashMap(); freeMarkerData.put("user", "Mr Man"); try { template.process(freeMarkerData, response.getWriter()); } catch (TemplateException e) { throw new ServletException(e); } } }