教你搭建Tiles工程-HelloTiles(附源码)

 1. 添加Tiles的jar依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
< 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. 配置web.xml,使用Tiles监听器,配置加载tiles容器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<? 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. 定义模板的结构,并使用JSP表现这个结构。

       3.1 模板的结构

wKioL1Qb4a6gYVWwAACg1S4p2Zo947.jpg

    3.2 创建HelloTiles.jsp文件

1
2
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
< tiles:insertDefinition  name = "myapp.homepage"  />

    

    4. 在web下创建tiles.xml,定义Tiles模板

1
2
3
4
5
6
7
8
9
10
11
12
13
<? 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. 项目结构图

wKioL1Qb4mmD2MzcAAFSlD6A1aE307.jpg

   

     6. 源码下载地址:http://pan.baidu.com/s/1eQ5q3QU





本文转自 genuinecx 51CTO博客,原文链接:http://blog.51cto.com/favccxx/1555193,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值