`
cherubo
  • 浏览: 4956 次
  • 来自: ...
文章分类
社区版块
存档分类

sitemesh简单应用

阅读更多
web开发当中,前端的页面逻辑很难被重用,当我们在每一个页面中用include来复用公共的header, css, js,footer时,会大量的出现重复的代码,无形中增加的开发人员的负担.sitemesh通过filter截取request和response,并给原始的页面加入一定的装饰(可能为header,footer...),然后把结果返回给客户端,并且被装饰的原始页面并不知道sitemesh的装饰,这也就达到了脱耦的目的。
SiteMesh 是opensymphony项目,下是官网中的介绍:
SiteMesh is a web-page layout and decoration framework and web- application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required.

SiteMesh intercepts requests to any static or dynamically generated HTML page requested through the web-server, parses the page, obtains properties and data from the content and generates an appropriate final page with modifications to the original. This is based upon the well-known GangOfFour Decorator design pattern.

SiteMesh can also include entire HTML pages as a Panel within another page. This is similar to a Server-Side Include, except that the HTML document will be modified to create a visual window (using the document's Meta-data as an aid) within a page. Using this feature, Portal type web sites can be built very quickly and effectively. This is based upon the well-known GangOfFour Composite design pattern.

SiteMesh is built using Java 2 with Servlet, JSP and XML technologies. This makes it ideal for use with J2EE applications, however it can be integrated with server-side web architectures that are not Java based such as CGI (Perl/Python/C/C++/etc), PHP, Cold Fusion, etc...

SiteMesh is very extensible and is designed in a way in which it is easy to extend for custom needs.

WEB-INF  下decorator.xml文件
<decorators defaultdir="/WEB-INF/decorators">
    <!-- 不需要修饰的页面 -->
    <excludes>
        <pattern>/css/*</pattern>
        <pattern>/js/*</pattern>
        <pattern>/images/*</pattern>
        <pattern>/dojo/*</pattern>
        <pattern>/webwork/*</pattern>
        <pattern>/login.jsp*</pattern>
         <pattern>/register/*</pattern>
    </excludes>
    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>
     </decorators>


defaultdir为装饰页面所在的文件夹.



装饰页面main.jsp,主要的页面结构布局.

代码:

<%@ page contentType="text/html;charset=utf-8" language="java"%>
[color=red]<%@ taglib uri="sitemesh-decorator" prefix="decorator"%>
<%@ taglib uri="sitemesh-page" prefix="page"%>[/color]

<%
String path = request.getContextPath();
%>
<HTML>
	<HEAD>
	<TITLE><decorator:title default="main page" /></TITLE>

		<decorator:head />
	<link rel="stylesheet" type="text/css"
			href="<%=path%>/css/default.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tab.css" />
		<script language="javascript" src="<%=path%>/js/formControl.js"></script>
		<script language="javascript" src="<%=path%>/js/changePage.js"></script>
		<META http-equiv=ImageToolbar content=no>
	</HEAD>
	<BODY id=main>
		<jsp:include flush="true" page="/commont/header.jsp"></jsp:include>
		<DIV id=container>
			<DIV id=content style="height:500px">
				<decorator:body />			<DIV id=navigation>
					<A accessKey=3 name=menu></A>
					<H2 class=hide>
						Navigation
					</H2>
					<UL id=menuroot>
						<LI>
							<A title="index" accessKey=1 href="<%=path%>/index.jsp">Index</A>
						</LI>
						<LI>
							<A title="ListUser" accessKey=3
								href="<%=path%>/user/listUsers.action">ListUser</A>
						</LI>
						<LI>
							<A title="listWorkSum" accessKey=4
								href="<%=path%>/worksum/listWorkSums.action">listWorkSum</A>
						</LI>
	<LI>
							<A title="ListUser" accessKey=3
								href="<%=path%>/clickstream/clickstreams.jsp">ClickStream</A>
						</LI>
						<LI>
							<A title="monitor" accessKey=6
								href="<%=path%>/monitor/jamonadmin.jsp">monitor</A>
						</LI>
						<LI>
							<A title="workflow" accessKey=6
								href="<%=path%>/workflow/default.jsp">workflow</A>
						</LI>
						<LI>
							<A title="workflow" accessKey=4
								href="<%=path%>/workflow/workflowLogin.action">workflowAction</A>
						</LI>
						<LI>
							<A title="soap" accessKey=6
								href="<%=path%>/soap/default.jsp">soap</A>
						</LI>
						<LI>
							<A title="Logout" accessKey=5 href="<%=path%>/logout.jsp">Logout</A>
						</LI>
					</UL>
				</DIV>


			</DIV>
			<DIV id=header>
				Copyright © 2003-2005 cherubo All Rights Reserved
			</DIV>
			<jsp:include page="/commont/footer.jsp" />
	</BODY>
</HTML>

上面页面
以下列着全部标签: Decorator Tags Page Tags
被用于建立装饰器页面. 被用于从原始内容页面访问装饰器.
<decorator:head />
<decorator:body />
<decorator:title />
<decorator:getProperty />
<decorator:usePage />
<page:applyDecorator />
<page:param
 
<decorator:head />
插入原始页面(被包装页面)的head标签中的内容(不包括head标签本身)。
<decorator:body />
插入原始页面(被包装页面)的body标签中的内容。
<decorator:title [ default="..." ] />
插入原始页面(被包装页面)的title标签中的内容,还可以添加一个缺省值。


被修饰的页面
<html>
<head>
    <title>main</title> 

    
</head>
<body>
<div style="PADDING-TOP: 50px;">
<h1>
Welcome Into NewiKi System 
</h1>
<h3>In Newiki System,You Can:</h3>
<h3>You can do Anything!</h3>
<h3>It's Life ,Live It!</h3>
<h3>You Are Freedom!</h3>

</div>
 </body>
</html>

很简单,很清楚的结构.

WEB.XML
<filter>
	<filter-name>sitemesh</filter-name>
	   <filter-class>
	       com.opensymphony.module.sitemesh.filter.PageFilter
	   </filter-class>
	</filter>
        <filter-mapping>
		<filter-name>sitemesh</filter-name>
		<url-pattern>*.jsp</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>sitemesh</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>

当访问被装饰的页面时. 效果如附件二.
  • 大小: 36.8 KB
  • 大小: 61.8 KB
分享到:
评论
1 楼 sunbird69 2008-09-29  
cool~~~

相关推荐

    SiteMesh简单应用

    NULL 博文链接:https://takeme.iteye.com/blog/1716468

    sitemesh简单教程页面装配器

    sitemesh 应用 Decorator 模式,用 filter 截取 request 和 response,把页面组件 d,content,banner 结合为一个完整的视图。通常我们都是用 include 标签在每个 jsp 页面中来 断的包含各种header , ...

    sitemesh 完美合集 4个资料和jar文件

    sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and ...

    sitemesh

    SiteMesh是一个Web页面布局修饰框架, 用于构建包含大量页面, 需要一致的外观样式(look/fell), 导航和布局机制的大型网站. SiteMesh应用Decorator模式,用filter截取request和response,把页面组件head,content,...

    siteMesh例子

    SiteMesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and ...

    sitemesh-examples-hellowebapp

    这是一个非常简单的“ hello world” Web应用程序。 它演示了将页面装饰器应用于网站的内容。 它使用下载SiteMesh jar,并使用 WebServer运行示例。 本质上,它是Gradle可以立即运行的教程。 如果您的系统上未 ,...

    jsoup jar包

    复合页面,始终是一个开发web应用时必须面对的问题,对struts的titles有厌倦,听说sitemesh不错,尝试,原以为复杂,谁知用起来是那么地简单,太令人惊叹! 写下试用教程: 1.准备一个web项目,到sitemesh官方网站...

    Java后端知识图谱帮助Java初学者成长.rar

    本文首先会给出关于 java后台开发 和 前端适配 的一些建议学习路线,接着简单解释一些应用到的高频技术,帮助大家理解和学习,算是一个入门篇。 2.Java后台开发知识一览 1、后端 WEB服务器:Weblogic、Tomcat、...

    Grails 中文参考手册

    6.2.4 使用Sitemesh布局 6.3 标签库 6.3.1 简单标签 6.3.2 逻辑标签 6.3.3 迭代标签 6.3.4 标签命名空间 6.4 URL映射 6.4.1 映射到控制器和操作 6.4.2 嵌入式变量 6.4.3 映射到视图 6.4.4 映射到响应代码 6.4.5 映射...

    Struts2 in action中文版

    12.2.1 SiteMesh 266 12.2.2 Tiles 267 12.2.3 JFreeChart 269 12.3 内部组件系统 271 12.3.1 Bean 271 12.3.2 常量 272 12.3.3 注入 272 12.3.4 Struts内部扩展点 273 12.4 编写浏览路径插件 274 12.5 小结 278 第...

    java开发常用jar包

    Sitemesh 是一个基于WEB页面的布局、装饰以及应用整合的开源框架。它能帮助我们在由大量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的 banner,一致的版权,等等。它不仅仅能处理动态的内容,...

Global site tag (gtag.js) - Google Analytics