Apache Tiles is a popular and mostly used templating framework for java based web application.
Tiles became more popular because Struts 1.x uses Tiles as its default templating framework.
SpringMVC which is an MVC framework, like Struts, also supports integration of Tiles as its templating framework.
Let us see how we can integrate SpringMVC and Tiles.
You can download Tiles binaries from http://tiles.apache.org/ .
Step#1: Add the following tiles jars to WEB-INF/lib folder.tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
Step#2: Configure tiles integration in WEB-INF/dispatcher-servlet.xml
03 |
< bean id = "tilesConfigurer" class = "org.springframework.web.servlet.view.tiles2.TilesConfigurer" >
|
04 |
< property name = "definitions" >
|
06 |
< value >/WEB-INF/tiles.xml</ value >
|
11 |
< bean id = "viewResolver" class = "org.springframework.web.servlet.view.UrlBasedViewResolver" >
|
12 |
< property name = "viewClass" value = "org.springframework.web.servlet.view.tiles2.TilesView" />
|
Step#3: Configure tiles definitions in WEB-INF/tiles.xml
06 |
< definition name = "baseLayout" template = "/jsp/layout/layout.jsp" >
|
07 |
< put-attribute name = "title" value = "SivaLabs" />
|
08 |
< put-attribute name = "header" value = "/jsp/layout/header.jsp" />
|
09 |
< put-attribute name = "navigation" value = "/jsp/layout/navigation.jsp" />
|
10 |
< put-attribute name = "body" value = "" />
|
11 |
< put-attribute name = "footer" value = "/jsp/layout/footer.jsp" />
|
14 |
< definition name = "login" extends = "baseLayout" >
|
15 |
< put-attribute name = "title" value = "SivaLabs : Login" />
|
16 |
< put-attribute name = "navigation" value = "" />
|
17 |
< put-attribute name = "body" value = "/jsp/login.jsp" />
|
20 |
< definition name = "welcome" extends = "baseLayout" >
|
21 |
< put-attribute name = "title" value = "SivaLabs : Welcome" />
|
22 |
< put-attribute name = "body" value = "/jsp/welcome.jsp" />
|
Step#4: Code the layout JSPslayout.jsp
04 |
< title >< tiles:insertAttribute name = "title" ignore = "true" /></ title >
|
05 |
< script type = "text/javascript" src = "js/sivalabs.js" ></ script >
|
09 |
< table border = "1" style = "border-collapse: collapse;" cellpadding = "2" cellspacing = "2" align = "center" width = "800" > < tbody >< tr >
|
10 |
< td height = "30" colspan = "2" >< tiles:insertAttribute name = "header" /></ td >
|
13 |
< td width = "150" height = "450" valign = "top" >
|
15 |
< tiles:insertAttribute name = "navigation" />
|
18 |
< td valign = "top" width = "650" >
|
20 |
< tiles:insertAttribute name = "body" />
|
25 |
< td height = "30" colspan = "2" >
|
27 |
< tiles:insertAttribute name = "footer" />
|
31 |
</ tbody ></ table ></ body >
|
header.jsp
1 |
< h2 >SivaLabs : My Experiments On Technology</ h2 >
|
footer.jsp
2 |
< b >© 2011 SivaLabs All Rights Reserved</ b >
|
navigation.jsp
1 |
< p >< a href = "createUser.do" >Create User</ a ></ p >< p >< a href = "listUsers.do" >View Users</ a ></ p >< p >< a href = "logout.do" >Logout</ a ></ p >
|
welcome.jsp
1 |
< h2 >Welcome to SpringMVC+Tiles Sample Application </ h2 >
|
Step#5: WelcomeController.java
01 |
package com.sivalabs.web.controllers;
|
03 |
import org.springframework.stereotype.Controller;
|
04 |
import org.springframework.web.bind.annotation.RequestMapping;
|
07 |
public class WelcomeController
|
09 |
@RequestMapping ( "welcome" )
|
10 |
public String welcome()
|
Here the String "welcome" will be resolved as a tile name and display the UI as per "welcome" tile configuration.
相关推荐
spring mvc的视图解析器有很多种,常用的比如internalresourceViewResolver,此资源为为使用tilesViewResolver的小demo
Tiles框架入门教程示例(含Springmvc),简单的springmvc整合tiles框架,maven管理
Apache Tiles3整合SpringMvc Apache Tiles3整合SpringMvc
这是springmv4整合tiles3,本人亲测是可以的。
提供的源码包括 SpringMVC+Apache Shiro的整合 SpringMVC+Apache Shiro+JPA(hibernate)整合配置
maven构建web工程,springmvc4整合tiles布局框架,配置基于java注解方式,没有xml文件
springMVC整合的
这里我只讲解jsp版本的,与servlet和SpringMVC整合,两种方式的应用。这里提供了纯servlet使用的代码,可以完成一个简单的新闻发布系统,做的比较简单,但是代码写的很详细,根据你自己的需求可以补充的。如果想和...
集成上面三大框架, 里面有解析Ibatis的简单用法。
Maven2.0.11_SpringMVC2.5_Tiles2.0.5开发的一个小例子,里面附有自己写的一个运行指南,很详细,可以实际运行。
springmvc整合mybatis的jar包,有需要的可以下载一下看看
mybatis和springmvc的整合,包含公司日常开发常用最基础的功能,文档详细介绍mybatis由浅入深,一步步以springmvc的整合,并实现增删改查
在整合的时候需要用到的jar包,springmvc整合redis需要的三个jar包,
简单整合,不是spring-data,无api操作示例
Springmvc整合Mybatis的小项目
项目由maven构建,使用springMVC整合了Redis的集群,发布到tomcat中,访问http://localhost:8080/SpringRedisCluster/redis/hello.do测试即可,前提是配好了redis的集群。
此版本为springMvc整合版 有时候开发者想要的不一定是一个大而全的项目,而是可以集成到适合我们项目中的Demo。 支付宝 扫码支付、电脑支付、WAP支付 微信 扫码支付(模式一二)、公众号H5支付、WAP支付 springMvc...
springMVC整合cxf所需的jar包
spring整合hibernate所需所有jar包
springmvc demo,整合了hibernate4作为dao层实现。使用c3p0连接池管理连接。