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中整合Apache Tiles,可以将页面设计与业务逻辑分离,提高代码的可维护性和复用性。 在Spring MVC中,视图解析器扮演着重要的角色,它负责将处理完的模型数据转换成具体的视图展现给用户。`...
在本教程中,我们将深入探讨如何将Tiles与SpringMVC整合,以实现更高效的页面构建。 首先,我们需要理解Tiles的核心概念。Tiles框架基于Apache Struts项目,其主要思想是定义模板(Tiles),这些模板是页面的可重用...
SpringMVC、Freemarker和Apache Tiles是三个在Web开发中广泛应用的框架,它们各自承担着不同的职责。SpringMVC是Spring框架的一部分,主要用于构建基于Java的后端 MVC(Model-View-Controller)应用程序;Freemarker...
SpringMVC4与Tiles3整合教程 在Java Web开发中,SpringMVC作为一个强大的MVC框架,被广泛用于构建后端逻辑,而Tiles3则是一个视图层框架,主要用于页面布局和组合。将两者整合可以使得应用的视图管理更加灵活高效。...
Apache Tiles3 是一个强大的视图框架,用于构建和管理网页应用中的页面布局。它允许开发者定义页面模板,然后通过组合这些模板来创建复杂的页面结构。Spring MVC 是一款流行的基于模型-视图-控制器(MVC)设计模式的...
《Maven2.0.11_SpringMVC2.5_Tiles2.0.5:构建高效Web应用的综合指南》 在Web应用程序开发领域,Maven、Spring MVC和Tiles是三个至关重要的组件,它们共同构建了一个强大而高效的开发框架。本指南将深入解析这些...
整合SpringMVC与Apache Tiles的步骤如下: 1. 添加依赖:在项目的pom.xml或build.gradle文件中,添加SpringMVC和Apache Tiles的依赖库。 2. 配置SpringMVC:在Spring的配置文件(如spring-servlet.xml)中,添加...
SSM(Spring、SpringMVC、MyBatis)是一个经典的Java web开发框架组合,广泛应用于企业级应用...在实际开发中,还可以结合其他工具和框架,如Hibernate、Spring Boot、Apache Tiles等,来进一步增强应用的功能和性能。
2. 配置Spring MVC:在`springmvc-servlet.xml`配置文件中,我们需要配置一个视图解析器,例如`UrlBasedViewResolver`,然后为Tiles设置一个特定的视图解析器,如`TilesViewResolver`。这样,Spring MVC就能识别并...
在实际项目中,通常会配合其他组件,如Apache Tiles进行视图管理,Hibernate或JPA进行更高级的ORM,以及Spring Security进行权限控制。 总的来说,SpringMVC+Spring+Mybatis框架组合提供了完整的MVC设计模式解决...
它整合了多种开源技术,如Freemarker和Tiles,为视图层提供了更多的选择。Struts2还支持国际化和主题,增强了用户体验。 5. **Hibernate**: Hibernate 是一个对象关系映射(ORM)框架,它简化了Java应用与数据库...
Struts是Apache软件基金会旗下的一款开源Java Web框架,主要用于构建基于MVC(Model-View-Controller)模式的Web应用程序。这个“级好的stucts入门实例程序”包含了一系列基础的Struts框架应用和相关的知识点,适合...