- 1、本文档共17页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
web架构设计与开发
一、实验内容
<decorator:usePage>、<decorator:useHtmlPage>和<decorator:head>标签使用
二、实例代码
1、struts.xml
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"/dtds/struts-2.0.dtd">
<struts>
<!-- Action所在包定义 -->
<package name="C10.1" extends="struts-default">
<!-- 直接导航的的Action定义 -->
<action name="randomimagePage">
<result>/jsp/image.jsp</result>
</action>
<action name="index" >
<result type="redirect">/jsp/body/firstPage.jsp</result>
</action>
</package>
</struts>。
2、3PartLayoutTemplate.jsp
<%@ page contentType="text/html; charset=gb2312"%>
<%@ taglib uri="/sitemesh/decorator" prefix="decorator"%>
<%@ taglib uri="/sitemesh/page" prefix="page"%>
<html>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!-- 使用decorator:head显示被装饰页面的head标签中内容(除title以外) -->
<decorator:head />
<head>
<title><decorator:title default="sitemesh页面" /></title>
<link href="<%=basePath%>/css/css.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#f7c800" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br><jsp:include page="/jsp/layout/head.jsp" flush="true" />
<table width="760" height="105" border="0" align="center" cellpadding="0" cellspacing="0" id="head">
<!-- 使用decorator:usePage标签,打印出被装饰页面的body等标签的属性内容 -->
<!-- usePage相当于JSP中<useBean>标签定义的JavaBean类名 -->
<decorator:usePage id="usePage" />
<tr >
<td align="center" colspan=2>
<h2>使用decorator:usePage标签各属性内容:</h2>
</td>
</tr>
<%
//取得被装饰页面的标签属性名,作为key值组合成一字符串数组。
String[] element = usePage.getPropertyKeys();
for(int i=0;i<element.length;i++) {%>
<tr >
<td align="right" >
<%=i+1%>
</td>
<td >
<!-- 各元素为被装饰页面标签属性名,作为key值,由 getProperty方法得到value即属性内容-->
<%=element[i]%>:<%=usePage.getProperty(element[i])%>
</td>
</tr>
<%
文档评论(0)