<servlet>
<servlet-name>WebMacroServlet</servlet-name>
<servlet-class>org.webmacro.servlet.WebMacroServlet</servlet-class>
<init-param>
<param-name>TemplateDir</param-name>
<param-value>/path/to/templates</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>WebMacroServlet</servlet-name>
<url-pattern>*.wm</url-pattern>
</servlet-mapping>
html
<html>
<body>
<h1>Hello, $name!</h1>
</body>
</html>
import org.webmacro.Context;
import org.webmacro.servlet.ServletContextFactory;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Context context = ServletContextFactory.getDefaultContext(request, response, getServletContext());
context.put("name", "WebMacro");
response.setContentType("text/html");
try {
context.getBroker().getTemplate("hello.wm").produceOutput(context, response.getWriter());
} catch (WebMacroException e) {
e.printStackTrace();
}
}
}