1. Add tiles jar Dependencies
<dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-api</artifactId><version>3.0.4</version></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-core</artifactId><version>3.0.4</version></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-jsp</artifactId><version>3.0.4</version></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-el</artifactId><version>3.0.4</version></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-extras</artifactId><version>3.0.4</version></dependency> <dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-servlet</artifactId><version>3.0.4</version></dependency>
2. Configure web. XML, use the tiles listener, and configure to load the tiles container
<?xml version="1.0" encoding="UTF-8"?><web-app id="pum" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Archetype Created Web Application</display-name> <context-param><param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name><param-value> /WEB-INF/tiles.xml </param-value></context-param> <listener> <listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class></listener><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
3. Define the template structure and use JSP to express this structure.
3.1 template Structure
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/D8/wKioL1Qb4a6gYVWwAACg1S4p2Zo947.jpg "Title =" layout.png "alt =" wkiol1qb4a6gyvwwaacg1s4p2zo947.jpg "/>
3.2 Create a hellotiles. jsp file
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %><tiles:insertDefinition name="myapp.homepage" />
4. Create tiles. XML in the Web and define the tiles template.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"><tiles-definitions> <definition name="myapp.homepage" template="/WEB-INF/layouts/classic.jsp"> <put-attribute name="title" value="Tiles tutorial homepage" /> <put-attribute name="header" value="/WEB-INF/tiles/banner.jsp" /> <put-attribute name="menu" value="/WEB-INF/tiles/common_menu.jsp" /> <put-attribute name="body" value="/WEB-INF/tiles/home_body.jsp" /> <put-attribute name="footer" value="/WEB-INF/tiles/credits.jsp" /> </definition></tiles-definitions>
5. Project Structure
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/D8/wKioL1Qb4mmD2MzcAAFSlD6A1aE307.jpg "Title =" directory.png "alt =" wkiol1qb4mmd2mzcaafsld6a1ae307.jpg "/>
6. Source: http://pan.baidu.com/s/1eQ5q3QU
This article from the "dust wind with the shadows of the Sky" blog, please be sure to keep this source http://favccxx.blog.51cto.com/2890523/1555193
How to build a tiles project-hellotiles (with source code)