惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
A
About on SuperTechFans
U
Unit 42
MyScale Blog
MyScale Blog
J
Java Code Geeks
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
D
Docker
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
量子位
月光博客
月光博客
G
Google Developers Blog
V
V2EX
博客园 - 聂微东
宝玉的分享
宝玉的分享
IT之家
IT之家
Vercel News
Vercel News

博客园 - deadshot123

tmplog javascript时间toString在java中转换成Date的测试代码 - deadshot123 - 博客园 在windows xp sp2 下修复 mdac 2.8 OutLook风格的菜单 td上长英文单词换行 时间控件最终版 点击改变颜色的日历(上篇改一行代码) 博客上的日历控件的初步实现 W3wp.exe内存占用问题以及如何查看一个网站对应的w3wp.exe(转) test 分批提交数据(删除大数据量时候用) 在C#中运用SQLDMO备份和恢复SQL Server数据库 (转) Bat文件编写方法(转) Visual Studio 2005常用插件搜罗 (转) oracle使用numtoyminterval来添加准确的月或者年 2003 server iis默认不解析asp 小知识:象素与字号的换算(转) .net学习计划 关于xp+ie7下,执行confirm会出现点击取消也执行submit的问题解决方案
struts-tiles初学 - deadshot123 - 博客园
deadshot123 · 2007-07-04 · via 博客园 - deadshot123

tiles,俗称"小部件"。由于当今界面设计的可用性要求界面必须保持一致。早期开发使用文件包含的方式来使页面模块化,类型<%@include file=""%> <jsp:include page="">之类的包含指令或jsp标签。这样导致所有包含这些的页面都必须添加类似代码。(tiles类型asp.net2.0的masterpage)

   Q:tiles比包含方式有哪些优先点?

   A:tiles可替换,扩展,继承,代码量小,是否还有别的区别必须深入研究。

   配置tiles

   一、先配置web.xml
在myeclipse上加入struts支持,在WEB-INF下会出现一系列的tld,例struts-bean.tld.

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<jsp-config>

<taglib>
<taglib-uri>/tags/tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld </taglib-location>
 </taglib> <taglib>
<taglib-uri>/tags/html.tld</taglib-uri>
 <taglib-location>/WEB-INF/html.tld </taglib-location> </taglib>
</jsp-config>
</web-app>
这些配置仅仅是为了方便使用。

   webroot下增加如下结构的文件夹

   webroot

      --tiles

         --layout

      --css

      --page

   并分别放header.html,body.html,footer.html放在webroot-tiles文件夹下,都只包括片段代码类似<h1>this is header html!</h1>

二、第一种tiles

   1)定义一个模板页simpletemplate.jsp放在webroot-tiles-layout文件夹下

<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="/tags/tiles.tld" prefix="tiles" %>
<%@ taglib uri="/tags/html.tld" prefix="html" %>
<%@ taglib uri="/tags/bean.tld" prefix="bean" %>//web.xml中定义好的taglib-uri只是为了这里方便使用,如果这里直接用/WEB-INF/struts-bean.tld也可以了
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head></head><body>
<div><tiles:insert attribute="header"/></div>//页头
<div><tiles:insert attribute="body"/></div>页内容
<div><tiles:insert attribute="footer"/></div>页脚
</body>
</html>
    2)定义一个使用该模板的页面simple.jsp放在webroot-page文件夹下
<%@ page  pageEncoding="GBK"%>
<%@ taglib uri="/tags/tiles.tld" prefix="tiles" %>
<tiles:insert   page="/tiles/layout/template.jsp"   flush="true">
<tiles:put name="header" type="page"  value="/tiles/header.html" /> //如果在模板内有的属性在此处没有定义,则出错(如要忽略该错误,必须在simpletemplate.jsp中的<tiles:insert attribute="header" ignore="ture"/>加上ignore="true")
<tiles:put name="body" type="page"  value="/tiles/body.html" /> //或者可以使用<tiles:put name="body" type="string" value="this is a body">;value=(这里可以用expressionlanguage或者html代码)
<tiles:put name="footer" type="page"   value="/tiles/footer.html" />
</tiles:insert>
这样就定义完成一个简单的tiles应用
三、按照第二中的tiles,如果要添加一个页面 都必须要添加一个内容页面,类似body.html,为了避免页面越来越多,可以使用body-wrap技术。
<tiles:put name="body"><input type="button" value="test" tile="123"/></tiles:put>//这样就少建立一个body文件,body内容直接包含在<tiles:input></tiles:input>中了
四、定义,扩展