Struts2标签系列教程之s:include标签
Struts2提供了大量丰富的标签供使用,它不再像Struts1中一样,将种类标签进行分门列别,但可以根据其使用的用途用以区别。本文通过对 Struts2中数据标签的学习,来对Struts2中标签的学习起到一个抛砖引玉的作用。文中将介绍Action标签、Bean标签、Data标签、 Include标签、Param标签、Set标签、Text标签、Property标签等标签。
代码下载:
Struts2DataTags
四、<s:include>标签
<s:include>标签用于在当前页面中包含来自其它servlet或JSP页面的处理结果。由于是页面与页面(或servlet)之间的页面包含,因此不需要action来进行页面的跳转。
1.WebRoot\pages\dataTags\includeTag.jsp
<%@ page contentType=”text/html; charset=GBK” %>
<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Include Tag 示例</title>
</head>
<body>
<h2>Include Tag 示例</h2>
<s:include value=”myBirthday.jsp” />
</body>
</html>
这里包含了另外一个页面myBirthday.jsp,其实相当于在JSP页面里包含其它的页面。原理一样的。
2.WebRoot\pages\dataTags\myBirthday.jsp
这个页面利用了上面所讲的<s:date>标签进行日期的格式化输出
<%@ page contentType=”text/html; charset=GBK” %>
<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Include Tag 示例</title>
</head>
<body>
<table border=”1″ width=”35%”>
<tr>
<td><b>Date Format</b></td>
<td><b>Date</b></td>
</tr>
<tr>
<td>Day/Month/Year</td>
<td><s:date name=”myBirthday” format=”dd/MM/yyyy” /></td>
</tr>
<tr>
<td>Month/Day/Year</td>
<td><s:date name=”myBirthday” format=”MM/dd/yyyy” /></td>
</tr>
<tr>
<td>Month/Day/Year</td>
<td><s:date name=”myBirthday” format=”MM/dd/yy” /></td>
</tr>
<tr>
<td>Month/Day/Year Hour<B>:</B>Minute</td>
<td><s:date name=”myBirthday” format=”MM/dd/yy hh:mm” /></td>
</tr>
<tr>
<td>Month/Day/Year Hour<B>:</B>Minute<B>:</B>Second</td>
<td><s:date name=”myBirthday” format=”MM/dd/yy hh:mm:ss” /></td>
</tr>
<tr>
<td>Nice Date (Current Date & Time)</td>
<td><s:date name=”myBirthday” nice=”false” /></td>
</tr>
</table>
</body>
</html>
3.Struts.xml配置
<action name=”includeTag”>
<result>/pages/dataTags/includeTag.jsp</result>
</action>
4.运行效果

图4.<s:include>标签

