user2986897
user2986897

Reputation: 51

Error resolving template "home", template might not exist or might not be accessible by any of the configured Template Resolvers

I'm using mvc + java HttpServlet + Thymeleaf template but it's error. File home.html has exist.

My code bellow:

        ServletContextTemplateResolver templateResolver 
                    = new ServletContextTemplateResolver();
        // XHTML is the default mode, but we will set it anyway for better understanding of code
        templateResolver.setTemplateMode("HTML5");
        templateResolver.setPrefix("D:\\development\\projects\\fpt.eclick.framework.web.thyme\\views\\");
        templateResolver.setSuffix(".html");
        templateResolver.setCacheTTLMs(3600000L);
        TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);
        WebContext ctx = new WebContext(request, response, request.getServletContext(), request.getLocale());

        try {
            templateEngine.process("home", ctx, response.getWriter());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 1000);

With Freemarker I used similar to and it's well done.

Thankyou very much

Upvotes: 0

Views: 4273

Answers (1)

Rafal Borowiec
Rafal Borowiec

Reputation: 5244

The problem is with the location (prefix) of the templates directory. Change it to the one available in context root of your web application, e.g. /WEB-INF/templates.

Upvotes: 1

Related Questions