views:

19

answers:

1

Hi, I'm writing Sping MVC based application all my methods inside a controller return ModelAndView objects.

What I would like to do is to apply standard HTML footer on each JSP page, like signup/signin/about us/contact use/etc... Is there any way I can do it within a controller? I know that I can use

<%@ include file="footer.jsp" %>

but I'm sure that there should be more elegant way to do that.

+1  A: 

Something like this is purely the responsibility of the view layer - the controllers should not know that the views have a common anything; the controllers only know the name of the view.

So how you can implement this depends entirely on which view-layer technology you use. If using JSP, you can simple include the footer.jsp in each jsp view, or use a tool like Sitemesh (which is great) to be able to capture common layouts in a single file. If using a template engine like Velocity, it's trivial to also set up common "layouts" which can capture the common logic - like the presence of a header, menu, footer etc - in a single place and then load the content template for each individual page.

matt b
OK, thank you, this is what I thought.
danny.lesnik