Using a page template with Tiles

With a page template, avoid repeating the common elements of the pages (HTML head, header, footer, navigation, and so on) in every JSP.

How to do it…

Here are the steps to use Tiles:

  1. Add the Tiles Maven dependencies in pom.xml:
    <dependency>
      <groupId>org.apache.tiles</groupId>
      <artifactId>tiles-servlet</artifactId>
      <version>3.0.5</version>
    </dependency>
    
    <dependency>
      <groupId>org.apache.tiles</groupId>
      <artifactId>tiles-jsp</artifactId>
      <version>3.0.5</version>
    </dependency> 
  2. In the Spring configuration class, remove the JSP view resolver (if it's there).
  3. Declare Tiles in the Spring configuration class:
    // declare Tiles configuration file @Bean public TilesConfigurer tilesConfigurer() { TilesConfigurer tilesConfigurer = ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.