一.简介

tiles是一种JSP布局框架,主要目的是为了将复杂的JSP页面作为一个页面的部分机能,然后组合成一个最终的页面,这种做法便于对各个页面机能的变更和维护,减少代码量,实现代码的重用。

tiles最早是被用作struts的组件(struts-tiles)来使用的,发展到现在已经可以和各种框架(spring,struts)整合使用。可参看其官网:官网

二.配置使用

1.相关jar包引用(这里是整合spring,spring mvc,maven)

pom.xml

<properties>
<spring.version>4.1.6.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cglib.version>2.2.2</cglib.version>
<hibernate.version>4.3.7.Final</hibernate.version>
<aspectj.version>1.8.4</aspectj.version>
<mysql.version>5.1.29</mysql.version>
<slf4j.version>1.7.7</slf4j.version>
<logback.version>1.1.2</logback.version>
<profile.id>${build.profile.id}</profile.id>
<tiles.version>3.0.5</tiles.version>
</properties>
<dependencies> <!--tiles系列-->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${tiles.version}</version>
</dependency> <dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${tiles.version}</version>
</dependency> <dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${tiles.version}</version>
</dependency> <dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${tiles.version}</version>
</dependency> <dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>${tiles.version}</version>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency> <dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--Cglib代理,Spring依赖-->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<!--aspect,织入库,Spring依赖-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.2</version>
</dependency>
<!--aspect库,Spring依赖-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- aop联盟定义的一组关于AOP的公共接口,Spring Aop依赖它 -->
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<!--java ee-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!--spring data jpa-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.0.0.RELEASE</version>
</dependency> <!--hibernate系列-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!--jpa support-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- JSR303规范及实现 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- JSR303规范的hibernate实现 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
<!--hibernate 的二级缓存 ehcache-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!--ehcache核心包-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.9</version>
</dependency>
<!--dbcp依赖-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Slf4j + logback的日志方案 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency> <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency> <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>

2.springmvc的配置文件中的解析器等的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!--配置自动扫描包-->
<context:component-scan base-package="com.ycitcxl.sssp"
use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan> <!--&lt;!&ndash;配置视图解析器&ndash;&gt;-->
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"-->
<!--p:prefix="/WEB-INF/jsp/"-->
<!--p:suffix=".jsp">-->
<!--</bean>-->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"
p:viewClass="org.springframework.web.servlet.view.tiles3.TilesView"
p:order="1"/> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"
p:preparerFactoryClass="org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory"
p:definitions-ref="definitions"/>
<util:list id="definitions">
<value>classpath:tiles.xml</value>
</util:list>
<!--视图解析配置-->
<mvc:view-resolvers>
<mvc:tiles view-names="tilesViewResolver"/>
<mvc:jsp prefix="/WEB-INF/jsp" suffix=".jsp" view-class="org.springframework.web.servlet.view.JstlView"/>
</mvc:view-resolvers>
<!--处理静态资源的默认servlet-->
<mvc:default-servlet-handler/>
<!--spring会自动注册一些bean来处理请求-->
<mvc:annotation-driven></mvc:annotation-driven>
</beans>

3.定义layout以及layout的component

layout/classic.jsp()

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<tiles:insertAttribute name="head" ignore="true"/> <title><tiles:insertAttribute name="title"/></title>
</head>
<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="menu"/>
<tiles:insertAttribute name="main"/>
<tiles:insertAttribute name="footer"/> </body>
</html>

header.jsp(页面的头部)

<%--
Created by IntelliJ IDEA.
User: 111
Date: 2016/2/6
Time: 13:10
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
<nav>
<ul style="list-style-type: none">
<li style="display: inline;"><span>微网站</span></li>
<li style="display: inline;"><span>微活动</span></li>
<li style="display: inline;"><span>微商城</span></li>
</ul>
</nav>
</head>

menu.jsp(左侧菜单页面)

<%--
Created by IntelliJ IDEA.
User: 111
Date: 2016/2/6
Time: 13:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<ul style="list-style-type: none">
<li>
<span>砸金蛋</span>
</li>
<li>
<span>刮刮卡</span>
</li>
<li>
<span>大转盘</span>
</li>
</ul>

footer.jsp(页面底部)

<%--
Created by IntelliJ IDEA.
User: 111
Date: 2016/2/6
Time: 14:10
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<footer>
<p>2010-2014 信息导航有限公司 京ICP备1200342号-1 京公网安备1101006035号</p>
</footer>

tiles.xml(tiles的配置文件)

<?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="layout.classic_act" template="/WEB-INF/jsp/lay/classic.jsp">
<put-attribute name="title" value="微活动"/>
<put-attribute name="menu" value="/WEB-INF/jsp/lay/menu.jsp"/>
<put-attribute name="header" value="/WEB-INF/jsp/lay/header.jsp"/>
<put-attribute name="footer" value="/WEB-INF/jsp/lay/footer.jsp"/>
</definition> </tiles-definitions>

home.jsp(页面调用)

<%--
Created by IntelliJ IDEA.
User: 111
Date: 2016/2/6
Time: 11:56
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<tiles:insertDefinition name="layout.classic_act">
<%--<tiles:putAttribute name="head"></tiles:putAttribute>--%>
<%--<tiles:putAttribute name="app"></tiles:putAttribute>--%> <tiles:putAttribute name="main">
<span>hello world!</span>
<span>
恭祝大家猴年大吉!
</span> </tiles:putAttribute>
</tiles:insertDefinition>

【tiles】简单使用总结的更多相关文章

  1. Cesium原理篇:3D Tiles(1)渲染调度

    Cesium在2016年3月份左右推出3D Tiles数据规范,在glTF基础上提供了LOD能力,定位就是Web环境下海量三维模型数据.虽然目前3D Tiles还是Beta阶段,有不少硬伤,但3D T ...

  2. Cesium原理篇:3D Tiles(1)渲染调度【转】

    Cesium在2016年3月份左右推出3D Tiles数据规范,在glTF基础上提供了LOD能力,定位就是Web环境下海量三维模型数据.虽然目前3D Tiles还是Beta阶段,有不少硬伤,但3D T ...

  3. Springmvc整合tiles框架简单入门示例(maven)

    Springmvc整合tiles框架简单入门示例(maven) 本教程基于Springmvc,spring mvc和maven怎么弄就不具体说了,这边就只简单说tiles框架的整合. 先贴上源码(免积 ...

  4. Tiles & SiteMesh

    Tiles & SiteMesh 这两天在给公司的新项目搭框架,在配tiles框架的时候发现一个小问题:    比如开发团队一共5人,每人10个页面,如果按照简单的tiles框架配置方法,每个 ...

  5. 分分钟知道tiles框架是干嘛的

    分分钟知道tiles框架是干嘛的 http://blog.sina.com.cn/s/blog_a123d4d50101792d.html参考上面的文章,简单明了.让你一下子就知道这个是用来做什么的. ...

  6. SpringMVC整合Tiles框架

    SpringMVC整合Tiles框架 Tiles组件 tiles-iconfig.xml Tiles是一个JSP布局框架. Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离 ...

  7. 教你如何精通Struts:Tiles框架

    Tiles框架特性和内容 Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离.它允许先创建模板,然后在运行时动态地将内容插入到模板中.Tiles 框架建立在JSP的inclu ...

  8. OpenLayers简单介绍以及简单实例

    OpenLayers是一个强大的JavaScript包,可以从它的官网免费下载.OpenLayers包含了很多强大的网页地图展示与操作功能,并且能够将不同源的图层展示在同一张地图中,支持各种第三方的地 ...

  9. POJ1979 Red and Black (简单DFS)

    POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

随机推荐

  1. ansible配置文件详解

    # ansible配置文件配置 配置项介绍 , 配置文件ansible.cfg, 运行playbook时,默认时在yaml文件所在路径寻找,然后再去/etc/ansible/下寻找 [defaults ...

  2. 阿里云centos安装docker

    近期转向core开发,mssql也支持了docker,索性把手上的一台服务改成centos做测试开发.中间安装docker碰到的问题做个记录. docker版本 docker从1.13版本之后采用时间 ...

  3. day26.面向对象-反射封装内置方法

    封装 隐藏对象的属性和实现细节,近对外提供公共访问方式 广义:代码保护,面向对象思想 狭义:将属性,方法隐藏起来 class Person: __key = 123456 # 私有的静态属性 def ...

  4. haproxy5-ssl

    配置实例: https://andyleonard.com/2011/02/01/haproxy-and-keepalived-example-configuration 配置haproxy支持htt ...

  5. mongodb不断刷日志的问题

    项目启动不断的循环刷日志. 在log4j.properties的配置文件中加上一行关闭即可 log4j.logger.org.mongodb.driver=OFF

  6. 1103_ddt 数据处理

    1.传入一个参数 import unittest from ddt import ddt,data,unpack @ddt class MyTestCase1(unittest.TestCase): ...

  7. 20165235 实现pwd功能

    20165235 实现pwd功能 要求 学习pwd命令 2.研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3.实现mypwd 测试mypwd 实现过程 pwd是将当前的文件目录 ...

  8. CF987B - High School: Become Human

    Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But ...

  9. windows下apache+https环境配置

    windows下apache+https环境配置 转 https://www.cnblogs.com/sandaizi/p/7519370.html 1.修改配置文件conf/httpd.conf,去 ...

  10. Ext使用中问题总结

    隐藏 Ext.form.DateField 的触发(trigger)元素使其内容不能修改并使其所有的文本框(text field)显示格式为Y-m-d items : [{ xtype : ' dat ...