How do I add .jsp headers and footers to my Spring MVC web app?
I know there's many different answers, but I would like to know (them all really but more importantly) what is the proper way to do this? I'm just learning Spring and I have a hint the answer lies with HandlerInterceptor. For now, I might just do so .jsp includes. Even with this include solution, could you detail where I would place the headers/footers structurally? Any advice or direction would be great.
I found your question whilst researching :-) Not sure if my solution is
<good | bad | a hack | already exists>
or if there is a better way but it's working for my current project.In your
myapp-servlet.xml
you can extend the viewResolver viewClass with your own implementation:myapp-servlet.xml
By overriding the renderMergedOutputModel you can force all views to really be a template in which you can define your global layout and then simply
<jsp:include/>
your partial(s).JstlView.java
If you look Spring's InternalResourceView.java you'll get a better idea of what Spring is doing when determining what view to use.
template.jsp
How to obtain request / session / servletcontext attribute in JSP using EL? helped me here with getting the attribute value
${partial}
out.simple_partial.jsp
Then in a controller, return the
simple_partial
viewApp.java
which will get wrapped by the
template.jsp
and responded out.I'd recommend SiteMesh first and Tiles second.