DaFoot
DaFoot

Reputation: 1557

Why is my browser downloading file instead of rendering SpringBoot & Sitemesh output?

I'm trying to use SpringBoot with Freemarker and Sitemesh.

When I go to a URL at the moment the request is handled by the application, data loaded and HTML output generated, but for some reason the browser has decided it wants to download the file (which contains the correct content) rather than rendering it as a page.

This was working a while back, trouble is I'm not sure which change I've made has broken it!

Sitemesh filter:

@WebFilter
public class SitemeshFilter extends ConfigurableSiteMeshFilter {

private static final Logger LOG = Logger.getLogger(SitemeshFilter.class);

    @Override
    protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
        LOG.debug("SiteMeshFilter creation");
        builder.addDecoratorPath("/*", "/templates/main.ftl")
            .addExcludedPath("/h2console/*");
    }
}

Application:

@ServletComponentScan
@SpringBootApplication
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class ClubManagementApplication {

    private static Logger LOG = Logger.getLogger(ClubManagementApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ClubManagementApplication.class, args);
    }
}

Snippet of controller:

@Controller
public class ClubController {

    @Autowired
    ClubService clubService;

    @RequestMapping(value = {"Club/{id}","club/{id}"})
    public ModelAndView viewClub(@PathVariable("id") int clubId) {
        ModelAndView mv = new ModelAndView("club");
        ....
        return mv;
    }
}

EDIT: From the HttpServletRequest object in controller... accept : text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8

In the response headers: Content-Type : application/octet-stream;charset=UTF-8

I guess the content type is the problem....just gotta find why it's being set like that.

Upvotes: 3

Views: 2309

Answers (1)

DaFoot
DaFoot

Reputation: 1557

In case someone else stumbles on this question, I changed my template file from an ftl to a html extension and suddenly it has woken up.

@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder)   {
    LOG.debug("SiteMeshFilter creation");
    //builder.addDecoratorPath("/*", "/templates/main.ftl");
    builder.addDecoratorPath("/*", "/templates/main.html");
}

Upvotes: 2

Related Questions