<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評(píng)論 :: 0 Trackbacks

    Spring Tiles Integration

    In this example you will learn how to integrate Spring with Tiles 2. The directory structure of the example is shown below.

    Add the following library files to the lib directory.

    01.antlr-runtime-3.0
    02.commons-logging-1.0.4
    03.org.springframework.asm-3.0.0.M3
    04.org.springframework.beans-3.0.0.M3
    05.org.springframework.context-3.0.0.M3
    06.org.springframework.context.support-3.0.0.M3
    07.org.springframework.core-3.0.0.M3
    08.org.springframework.expression-3.0.0.M3
    09.org.springframework.web-3.0.0.M3
    10.org.springframework.web.servlet-3.0.0.M3
    11. 
    12.commons-beanutils-1.7.0
    13.commons-digester-1.8
    14.commons-logging-api-1.1
    15.jstl
    16.standard
    17.tiles-api-2.0.4
    18.tiles-core-2.0.4
    19.tiles-jsp-2.0.4

    You will see how to create a simple classic tile layout with a header, menu, body and footer regions.


    In Spring to use Tiles, configure the following Tile definition in the Spring configuration file.

    01.<?xml version="1.0" encoding="UTF-8"?>
    02.<beans xmlns="http://www.springframework.org/schema/beans"
    03.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    04.    xmlns:p="http://www.springframework.org/schema/p"
    05.    xmlns:context="http://www.springframework.org/schema/context"
    06.    xsi:schemaLocation="
    07.    http://www.springframework.org/schema/beans
    08.    http://www.springframework.org/schema/beans/spring-beans.xsd
    09.    http://www.springframework.org/schema/context
    10.    http://www.springframework.org/schema/context/spring-context.xsd">
    11.     
    12.    <bean id="viewResolver" class="org.springframework.web.servlet.view. ResourceBundleViewResolver" p:basename="views" />
    13.     
    14.    <context:component-scan base-package="com.vaannila.web" />
    15.     
    16.    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2. TilesConfigurer" p:definitions="/WEB-INF/tiles-defs.xml" />   
    17.         
    18.</beans>

    Using the definitions attribute specify the location of the tiles definition file. Here the location is "/WEB-INF/tiles-defs.xml". The tiles definition file is shown below.

    01.<?xml version="1.0" encoding="UTF-8" ?>
    02. 
    03.<!DOCTYPE tiles-definitions PUBLIC
    04.       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
    05.       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
    06. 
    07.<tiles-definitions>
    08. 
    09.  <definition name="baseLayout" template="/WEB-INF/tiles/baseLayout.jsp">
    10.      <put-attribute name="title"  value="Template"/>
    11.      <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
    12.      <put-attribute name="menu"   value="/WEB-INF/tiles/menu.jsp"/>
    13.      <put-attribute name="body"   value="/WEB-INF/tiles/body.jsp"/>
    14.      <put-attribute name="footer"   value="/WEB-INF/tiles/footer.jsp"/>
    15.  </definition>
    16.   
    17.  <definition name="welcome" extends="baseLayout">
    18.      <put-attribute name="title"  value="Welcome"/>
    19.      <put-attribute name="body"   value="/WEB-INF/jsp/welcome.jsp"/>     
    20.  </definition>
    21.   
    22.  <definition name="friends" extends="baseLayout">
    23.      <put-attribute name="title"  value="Friends"/>
    24.      <put-attribute name="body"   value="/WEB-INF/jsp/friends.jsp"/>     
    25.  </definition>
    26.   
    27.  <definition name="office" extends="baseLayout">
    28.      <put-attribute name="title"  value="Office"/>
    29.      <put-attribute name="body"   value="/WEB-INF/jsp/office.jsp"/>     
    30.  </definition>
    31.   
    32.</tiles-definitions>

    Here we first define a base layout, later we extend the base layout and create three more tile definitions by changing only the title and the body regions.

    To dispaly views we use the ResourceBundleViewResolver. By default the views.properties file will be used to store the key value pairs, we specify this using the basename attribute.

    01.welcome.(class)=org.springframework.web.servlet.view.tiles2.TilesView
    02.welcome.url=welcome
    03. 
    04.friends.(class)=org.springframework.web.servlet.view.tiles2.TilesView
    05.friends.url=friends
    06. 
    07.office.(class)=org.springframework.web.servlet.view.tiles2.TilesView
    08.office.url=office
    09. 
    10.about.(class)=org.springframework.web.servlet.view.JstlView
    11.about.url=/WEB-INF/jsp/about.jsp

    The welcome, friends and office refers to the tile definition names (the one to right side of the = sign). For tile views we use "org.springframework.web.servlet.view.tiles2. TilesView" class. You can also have other views together with the tile views. The about url is mapped to the about.jsp page with is a org.springframework.web.servlet.view.JstlView.

    The baseLayout.jsp file contains the table structure to hold the different regions.

    <%@ 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>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><tiles:insertAttribute name="title" ignore="true" /></title>
    </head>
    <body>
    <table border="1" cellpadding="2" cellspacing="2" align="center">
    <tr>
    <td height="30" colspan="2">
    <tiles:insertAttribute name="header" />
    </td>
    </tr>
    <tr>
    <td height="250">
    <tiles:insertAttribute name="menu" />
    </td>
    <td width="350">
    <tiles:insertAttribute name="body" />
    </td>
    </tr>
    <tr>
    <td height="30" colspan="2">
    <tiles:insertAttribute name="footer" />
    </td>
    </tr>
    </table>
    </body>
    </html>

    Here we use annotated controller handler mapping to handle the request. In the redirect.jsp page we forward the request to the welcome.htm url.

    <% response.sendRedirect("welcome.htm"); %>

    The welcome.htm url will be handled by the WelcomeController class, where we forward it to the welcome tile page.

    package com.vaannila.web;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    public class WelcomeController {

    @RequestMapping("/welcome.htm")
    public String redirect()
    {
    return "welcome";
    }
    }

    You can download and try the example here.

    Source :Download
    War :Download

    posted on 2009-10-19 14:32 seal 閱讀(1993) 評(píng)論(0)  編輯  收藏 所屬分類: Springweb
    主站蜘蛛池模板: 亚洲国产精品成人精品软件 | 日本亚洲欧洲免费天堂午夜看片女人员| 国产午夜精品久久久久免费视| 亚洲AV无码专区日韩| 自拍偷自拍亚洲精品偷一| 精品国产免费一区二区| 精品国产亚洲第一区二区三区| 日韩激情淫片免费看| 美女视频黄a视频全免费网站一区 美女视频黄a视频全免费网站色 | 91老湿机福利免费体验| 国产a级特黄的片子视频免费 | 四虎必出精品亚洲高清| 最近中文字幕免费mv视频7| 亚洲综合在线一区二区三区| 国产麻豆免费观看91| 免费中文字幕视频| 亚洲乱码一区二区三区在线观看 | 国产高清视频免费在线观看| 久久亚洲国产精品五月天| 5g影院5g天天爽永久免费影院| 亚洲免费在线视频播放| 蜜臀91精品国产免费观看| 丰满少妇作爱视频免费观看| 亚洲av午夜福利精品一区 | 精品免费久久久久久久| 亚洲一区二区无码偷拍| 亚洲国产午夜福利在线播放| a级成人毛片免费图片| 亚洲国产中文在线二区三区免| 日韩一品在线播放视频一品免费| 人人爽人人爽人人片A免费| 亚洲尹人九九大色香蕉网站| GOGOGO免费观看国语| 亚洲一区二区三区日本久久九| 成人免费网站在线观看| 无码日韩人妻AV一区免费l| 国产成人免费高清在线观看| 久久WWW免费人成—看片| 亚洲国产成AV人天堂无码| 亚洲精品tv久久久久| 1000部无遮挡拍拍拍免费视频观看|