博客统计信息

51cto推荐博客
用户名:Icansoft
文章数:128
评论数:167
访问量:1026788
无忧币:1770
博客积分:2511
博客等级:6
注册日期:2007-11-10

我的技术圈(0)

更多>>
Struts tiles入门(最最简单的例子)
2008-12-10 19:16:12
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://android.blog.51cto.com/268543/118611
       前提物质条件: 1.Struts Framework;    2.struts-tiles.tld

一. web.xml配置
<servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-confg.xml</param-value>
        </init-param>
        <init-param>        
                <param-name>definitions-config</param-name>            
                <param-value>/WEB-INF/tiles-defs.xml</param-value>        
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>

...
<taglib>
        <taglib-uri>/tags/struts-tiles</taglib-uri>
        <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>

二. struts-confg.xml配置
    <plug-in className="org.apache.struts.tiles.TilesPlugin">
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> 
    </plug-in>

三. tiles-defs.xml内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC    
    "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"    
    "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">

<tiles-definitions>
        <definition name="site.mainLayout"    path="/mainlayout.jsp">
                <put name="header" value="/header.html"/>
                <put name="body" value="/logon.jsp"/>
                <put name="footer" value="/footer.html"/>
        </definition>
</tiles-definitions>

四. mainlayout.jsp内容
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>tiles</title>
  </head>
  <body>
    <tiles:insert attribute="header" />
                <tiles:insert attribute="body" />
                <tiles:insert attribute="footer" />
  </body>
</html>

五.tiles的调用
index.jsp内容
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>

<tiles:insert definition="site.mainLayout" flush="true" />
或者(无需tiles-defs.xml)
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<tiles:insert template="mainlayout.jsp">
    <tiles:put name="title"    value="This is the title." />
    <tiles:put name="header" value="header.jsp" />
    <tiles:put name="body"     value="body.jsp" />
</tiles:insert>

调用index.jsp时就会引用mainlayout.jsp来显示。

本文出自 “学习Android” 博客,请务必保留此出处http://android.blog.51cto.com/268543/118611

分享至
更多
一键收藏,随时查看,分享好友!
0人
了这篇文章
类别:Java/J2EE技术圈()┆阅读()┆评论() ┆ 推送到技术圈返回首页

相关文章

文章评论

 
 

发表评论            

【技术门诊】专家解析:软考重点难点及应试技巧
昵  称:
登录  快速注册
验证码:

请点击后输入验证码博客过2级,无需填写验证码

内  容: