SPRINGMVC Integrated tiles Framework Simple Getting Started example (MAVEN)

Source: Internet
Author: User
Tags log4j

This tutorial is based on how springmvc,spring MVC and maven do not specifically say, this is simply the integration of tiles framework.

First paste the source code:
http://download.csdn.net/detail/zhangbing2434/9435460 (Here is idea,eclipse, there may be some differences when importing)

1. Tiles-dependent jar Package:




Maven Code:

<dependency> <groupId>commons-beanutils</groupId> <artifactid>commons-bean utils-core</artifactid> <version>1.8.3</version> </dependency> &LT;DEP Endency> <groupId>commons-digester</groupId> <artifactId>commons-digester<
            /artifactid> <version>2.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <versio n>1.2.15</version> </dependency> <dependency> <groupid>org.slf4j&lt
        ;/groupid> <artifactId>slf4j-api</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>org.slf4j</groupId> &L T;artifactid>slf4j-log4j12</artifactid> <version>1.4.2</version> </dependency> <dependen Cy> <groupId>org.apache.tiles</groupId> <artifactid>tiles-api</artifactid&
            Gt <version>2.2.1</version> </dependency> <dependency> <groupid>org .apache.tiles</groupid> <artifactId>tiles-core</artifactId> <version>2.2.1 </version> </dependency> <dependency> <groupid>org.apache.tiles</gr
        Oupid> <artifactId>tiles-jsp</artifactId> <version>2.2.1</version>
            </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-servlet</artifactId> <version>2.2.1</version> </dependen
 Cy>       <dependency> <groupId>org.apache.tiles</groupId> <artifactid>tiles- Template</artifactid> <version>2.2.1</version> </dependency>

2, Spring MVC Configuration Tiles Framework (springmvc-servlet.xml)

<bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.UrlBasedViewResolver" >
        < Property name= "Viewclass" >
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id= "Tilesconfigurer" class= " Org.springframework.web.servlet.view.tiles2.TilesConfigurer ">
        <property name=" Definitions ">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

3, Configuration tiles (tiles.xml)

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE tiles-definitions Public "-//apache software foundation//dtd tiles Configuration 2.0//en" "/http Tiles.apache.org/dtds/tiles-config_2_0.dtd "> <tiles-definitions> <definition name=" base.definition "Template="/jsp/templet.jsp "> <put-attribute name=" title "Value=" "/> <put-attribute na
            Me= "header" value= "/jsp/head.jsp"/> <put-attribute name= "menu" value= "/jsp/menu.jsp"/> <put-attribute name= "Body" value= ""/> <put-attribute name= "footer" value= "/jsp/foot.jsp"/> & lt;/definition> <definition name= "CustomerForm" extends= "base.definition" > <put-attribute name= "Ti 
    Tle "value=" hhhhhhh "/> <put-attribute name=" Body "value="/jsp/customerform.jsp "/> </definition> <definition name= "Customerdetail" extends= "base.definition" > <put-attribuTe name= "title" value= "dddddd"/> <put-attribute name= "Body" value= "/jsp/customerdetail.jsp"/> </de Finition> </tiles-definitions>
 where templet.jsp (base.definition) as a template, where the defined header,menu,body,footer need to configure their own corresponding JSP files, the general body is variable, and other fixed JSP. templet.jsp Code: 
<%@ taglib uri= "http://tiles.apache.org/tags-tiles" prefix= "tiles"%> <%@ page language= "java" pageencoding= " UTF-8 "%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  
   4. Effects 

Writing is not particularly good, we can download the source run up and see it, there are questions welcome message exchange

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.