Velocity ServletContext

PavolL April 17, 2014

Hi,

How I can access attributes from Velocity template stored in Servlet Context

I have listerer

public class StartListener implements ServletContextListener {

    private static final Logger log = LoggerFactory.getLogger(StartListener.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("App starts");

        ServletContext servletContext = sce.getServletContext();
        servletContext.setAttribute("links", new Links());
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.info("App ends");
    }
}

In servlet I can do

Links links = (Links) getServletContext().getAttribute("links");

But I want to accses "links" directly from velocity template.

1 answer

1 vote
Frédéric Tardieu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2014

Hi,

Did you try to do

${links}

in your Velocity template?

Fred

Suggest an answer

Log in or Sign up to answer