Spring Integrated Tiles

Source: Internet
Author: User

1. Assume that the spring-related packages and configurations have been successfully imported (there is time to make up the project with 3.2.0 version).

2. Import the tiles related jar package.

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

3. Increase the integration of spring and tiles and the configuration of tiles in Servlet.xml.

    <Beanclass= "Org.springframework.web.servlet.view.tiles2.TilesViewResolver" >        < Propertyname= "Order"value= "0" />    </Bean>    <BeanID= "Tilesconfigurer"class= "Org.springframework.web.servlet.view.tiles2.TilesConfigurer">        < Propertyname= "Definitions">            <List>                <value>/web-inf/pbx-views/tiles.xml</value>            </List>        </ Property>    </Bean>

4. Define a template for the site (style.jsp)

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"%><%@ taglib URI="Http://tiles.apache.org/tags-tiles"prefix="Tiles"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title></title></Head><Body>    <Div>        <Table>            <TR>                <TDcolspan= "2">                    <Tiles:insertattributename= "logo"/>                </TD>            </TR>            <TR>                <TDcolspan= "2">                    <Tiles:insertattributename= "Menu"/>                </TD>            </TR>            <TR>                <TD>                    <Tiles:insertattributename= "Body"/>                </TD>                <TD>                    <Tiles:insertattributename= "Advers"/>                </TD>            </TR>            <TR>                <TDcolspan= "2">                    <Tiles:insertattributename= "Footer"/>                </TD>            </TR>        </Table>    </Div></Body></HTML>

5. Associating page templates and 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>  <!--layout for index of Mycollege -  <definitionname= "Baselayout"Template= "/web-inf/pbx-views/frame/style1.jsp">    <Put-attributename= "logo"value= "/web-inf/pbx-views/frame/logo.jsp"/>    <Put-attributename= "Menu"value= "/web-inf/pbx-views/frame/menu.jsp"/>    <Put-attributename= "Body"value= "/web-inf/pbx-views/frame/body.jsp"/>    <Put-attributename= "Advers"value= "/web-inf/pbx-views/frame/advers.jsp"/>    <Put-attributename= "Footer"value= "/web-inf/pbx-views/frame/footer.jsp"/>  </definition>  <definitionname="*"extends= "Baselayout">      <Put-attributename= "Body"value= "/web-inf/pbx-views/{1}.jsp"/>  </definition>  </tiles-definitions>

PS: This is used to fit the page positioning.

6. You can then easily map it in the controller.

@Controller  Public class Indexcontroller {    = "/index")    public  String Index () {                // your service action          return "Home";    }}

7. Process grooming.

7.1 Index request was distributed to Indexcontroller by spring;

7.2 Indexcontroller carries out the related business process, returns the string home;

7.3 String Home is parsed by Tilesviewresolver and returns a

A combined page made up of logo.jsp/menu.jsp/home.jsp/advers.jsp/footer.jsp.

Spring Integrated Tiles

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.