MChan
MChan

Reputation: 7202

Templates in a Spring MVC web application

I have a lot of common areas in my web application design, for example footer, header sidebar, blocks...etc and going through all of the application JSP files to change something for example in the header is pretty hectic so I was wondering if I can make something like template files for common areas for example header template, sidebar template, footer template, then I can include such templates in any JSP inside my application?

I am using Spring MVC framework to build my application

Upvotes: 12

Views: 36915

Answers (4)

pappu_kutty
pappu_kutty

Reputation: 2488

I have used Apache Tiles. It can be very easily integrated with Spring MVC. You can also consider using sitemesh. As you mentioned header template, footer template you can have base template for header, footer, menu and you can integrate them into base template,

Note : You can only have jsp and not html here.

Check this link for spring with tiles.

http://www.springbyexample.org/examples/dynamic-tiles-spring-mvc-module.html

Upvotes: 3

Jk1
Jk1

Reputation: 11463

As for templating you have the following options:

  1. Custom JSP tags. These tags may exist as Java classes or JSP snippets and provide a basic facility to encapsulate and reuse parts of JSP pages (headers, footers, etc.). See more in this manual

  2. Template engines like Tiles or decorators like Sitemesh. They are quite powerfull in building complex page layouts.

If you're looking for custom UI themes support please take a look at custom themes support in Spring MVC.

Upvotes: 11

Ralph
Ralph

Reputation: 120871

If you want to seperate Header, Footer and some other common stuff from the "real" content, then you can use Apache Tiles.

It is easy to integrate in spring. So for example Spring Roo use it.

Upvotes: 1

Raja P
Raja P

Reputation: 3

Ideally yes, You need to create common files instead of redundant code because it might leads to many changes if u want to change a single thing. So try to use below code based on your requirement.

<%@ include is a static include, <jsp:include is a dynamic include.

Another solution: As you are using Spring framework try to use spring tiles search in google for more help for example SpringByExample

Upvotes: 0

Related Questions