Struts编程 Tiles的使用1——基于JSP的定义和属性

有两种方法可以创建Tiles定义并为应用程序指定他们的属性。如下:



方法 1:基于JSP的定义和属性
1. 建立工程S_Tiles,并在在struts-config.xml中添加 

<!-- Tiles定义-->
    
<plug-in className="org.apache.struts.tiles.TilesPlugin">
        
<set-property property="definitions-config"
            value
="/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-defs-baseinfo.xml" />
    
</plug-in>
2. 创建  header.jsp     footer.jsp     menu.jsp     body.jsp,代码如下:
<html:html lang="true">
<body>
    
<table  align="center">
         
            
<tr>
                
<td align="center">  
                    
<p><font color="blue">页头(This is header)</font> </p>

                
</td>
            
</tr>
         
    
</table>
</body>
</html:html>

##########################################################

<html:html >
  
<body>
   
<table  align="center">
         
            
<tr>
                
<td align="center">  
                    
<p><font color="blue">页脚(This is the footer)</font> </p>

                
</td>
            
</tr>
         
    
</table>
  
</body>
</html:html>

#############################################################

<html:html>
  
  
<body>
   
<table  align="center">
         
            
<tr>
                
<td align="center">  
                    
<p><font color="red">导航菜单(Here is the menu)</font> </p>

                
</td>
            
</tr>
         
    
</table>
  
</body>
</html:html>

#############################################################

<html:html>  
  
  
<body>

   
<table  align="center">
         
            
<tr>
                
<td align="center">  
                    
<p><font color="red">页体(Here is the body)</font> </p>

                
</td>
            
</tr>
         
    
</table>
  
</body>
</html:html>

3.  创建页面布局文件layout.jsp,代码如下:
<%@ page language="java" pageEncoding="gb2312"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">

<body>
    
<table align="center">
        
<tr>
            
<td colspan="2">
                
<tiles:insert attribute="header" />
            
</td>
        
</tr>
        
        
<tr>
            
<td width="15%">
                
<tiles:insert attribute="menu" />
            
</td>
            
<td>
                
<tiles:insert attribute="body" />
            
</td>
        
</tr>
        
        
<tr>
            
<td colspan="2">
                
<tiles:insert attribute="footer" />
            
</td>
        
</tr>
    
</table>
</body>
</html:html>
4.   最后创建引用 布局页面 layout.jsp  的页面 layoutResult.jsp
<%@ page language="java" pageEncoding="gb2312"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<tiles:insert page="/tiles/layout.jsp" flush="true">
    
<tiles:put name="title" value="Tiles" />
    
<tiles:put name="header" value="header.jsp" />
    
<tiles:put name="footer" value="footer.jsp" />
    
<tiles:put name="menu" value="menu.jsp" />
    
<tiles:put name="body" value="body.jsp" />
</tiles:insert>

 

6.最后项目结构如图:

5.访问layoutResult.jsp,便看到结果
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值