2.4.3.獲得標記
在模板JSP頁中使用<template:get>標記能夠檢索由<template:put>標記插入到JSP頁的資源。屬性如下:
屬性描述Name 由<template:put>標記插入的內容的名稱Role 如果設置了這個屬性,只有在當前合法用戶具有特定角色時才能進行內容的檢索
2.4.4.使用模板標記
首先編寫一個模板JSP頁,它將被所有的web頁使用:
<html>
<%@ taglib uri=”/template” prefix=”template” %>
<head>
<title></title>
</head>
<body>
<table width=”100%” height=”100%” >
<tr height=”10%”>
<td>
<template:get name=”header”/>
</td>
</tr>
<tr height=”80%”>
<td>
<template:get name=”content”/>
</td>
</tr>
<tr height=”10%”>
<td>
<template:get name=”footer”/>
</td>
</tr>
</table>
</body>
</html>
我們將這個文件命名為template.jsp。這個文件使用<template:get>標記來獲得由JSP頁使用<template:put>標記提供的內容,并且將內容在一個HTML表格中顯示出來。這三個內容是標題,內容和頁腳。典型的內容JSP會是這樣:
<%@ taglib uri=”/template” prefix=”/template” %>
<template:insert template=”template.jsp”>
<template:put name=”header” content=”header.html”/>
27
<template:put name=”content” content=”employeeList.jsp”/>
<template:put name=”footer” content=”footer.html”/>
</template:insert>
這個應用程序JSP頁使用<template:insert標記來定義模板,然后使用<template:put>標記將特定內容名稱指定的資源放到模板JSP頁中。如果我們有上百個布局相同的頁,但突然想改變這個模板,我們只需要改變template.jsp文件。
文章來源于領測軟件測試網 http://www.kjueaiud.com/