Rendering a Velocity Template from Your FishEye Servlet

Velocity allows your Servlet Plugins to render HTML pages from simple templates.This tutorial briefly shows the basics of using velocity. The FishEye Twitter Integration Plugin Tutorial shows velocity being used to generate a form for maintaining user preferences as part of a larger plugin.

Velocity templates are placed in the resources part of your plugin project, i.e. myplugin/src/main/resources/mytemplate.vm.

Your servlet uses Velocity like this:

public class MyServlet extends HttpServlet {
    private final VelocityHelper velocityHelper;

    @Autowired
    public MyServlet(VelocityHelper velocityHelper) {
        this.velocityHelper = velocityHelper;
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Map<String,Object> params = new HashMap<String,Object>();

        params.put("first", "Hello");
        params.put("second", "World");
        velocityHelper.renderVelocityTemplate("mytemplate.vm", params, response.getWriter());
    }
}

where mytemplate.vm contains:

<html>
<head>
</head>
<body>
  ${first}, ${second}.
</body>
</html>

In order to render the text "Hello, World.".

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport