Last updated Feb 19, 2024

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;

    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:

  ${first}, ${second}.

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

Rate this page: