java 装饰器sitemesh
1.配置环境
添加sitemesh-2.3.jar和struts2-sitemesh-plugin-2.1.6.jar
怎样配置环境除了要copy到WEB-INF/lib中的sitemesh.jar,copy到WEB-INF中的sitemesh- decorator.tld,sitemesh-page.tld文件外,还有2个文件要建立到WEB-INF/:sitemesh.XML(可选) decorators.xml
sitemesh.xml 可以设置2种信息:
PageParsers:负责读取stream的数据到一个Page对象中以被SiteMesh解析和操作。(不太常用,默认即可)
DecoratorMappers :不同的装饰器种类,我发现2种比较有用都列在下面。一种通用的mapper,可以指定装饰器的配置文件名,另一种可打印的装饰器,可以允许你当用http://ocalhost/aaa/a.html?printable=true方式访问时给出原始页面以供打印(免得把header,footer等的花哨的图片也搭上)(但一般不用建立它,默认设置足够了:com/opensymphony/module/sitemesh/factory/sitemesh-default.xml):
decorators.xml :定义构成复合视图的所有页面构件的描述(主要结构页面,header,footer...),如下例:
n="1.0" encoding="ISO-8859-1"?>
/ws/*
/js/*
/catagories-list*
/*
/welcome.ies
/login.ies
/logout.ies
defaultdir:包含装饰器页面的目录page:页面文件名name:别名role:角色,用于安全webapp:可以另外指定此文件存放目录Patterns:匹配的路径,可以用*,那些被访问的页面需要被装饰。
2.在main.jsp中
"-//W3C//DTD XHTML 1.1 Transitional//EN"
"https://www.360docs.net/doc/9f13105818.html,/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="decorator" uri="https://www.360docs.net/doc/9f13105818.html,/sitemesh/decorator" %>
<%@taglib prefix="page" uri="https://www.360docs.net/doc/9f13105818.html,/sitemesh/page" %>
<%@taglib prefix="s" uri="/struts-tags" %>
|
onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.sty
le.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > | onmouseover="this.style.backgroundColor='#9F9000';" onmouseout="this.style.backgroundColor='#0F0F6F';" onmousedown="this.style.backgroundColor='#9F5B00';" onmouseup="this.style.backgroundColor='#9F9000';" onclick="window.location='${url}'" style="cursor: pointer;" > |
|
|
|
|
|
/*
...
应用包装器到指定的页面上,一般用于被包装页面中主动应用包装器。这个标签有点不好理解,我们来看一个例子:
包装器页面/_decorators/panel.jsp:
...
并且在decorators.xml中有
一个公共页面,即将被panel包装:/_public/date.jsp:
...<%=newJava.util.Date()%> ...
被包装页面/page.jsp:
page的应用
.....
chen_p@https://www.360docs.net/doc/9f13105818.html,
最后会是什末结果呢?除了/page.jsp会被默认的
包装页面包装上header,footer外,page.jsp页面中还内嵌了date.jsp页面,并且此date.jsp页面还会被panel.jsp包装为一个title加body的有2段的页面,第1段是date.jsp的title,第2段是date.jsp的body内容。
另外,page:applyDecorator中包含的page:param标签所声明的属性值还可以在包装页面中用decorator:getProperty标签访问到。
*/
3.web.xml中配置
sitemesh
com.opensymphony.module.sitemesh.filter.PageFilter
sitemesh
/*