[转]decorators.xml的用法
原文地址:https://blog.csdn.net/laozhuxiao/article/details/54342121
简介:
sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and footer,现在,在sitemesh的帮助下,我们可以开心的删掉他们了
一、在WEB-INF/web.xml中copy以下filter的定义:
<filter>
<filter-name>sitemeshFilter</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemeshFilter</filter-name>
<url-pattern>/a/*</url-pattern>
</filter-mapping>
二、在WEB-INF下,建立一个decorators.xml配置文件,如下:
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/static">
<!-- 默认装饰页面, 在需要装饰的页面增加<meta name="decorator" content="default"/> -->
<decorator name="blank" page="layouts/blank.jsp" />
<decorator name="default" page="layouts/default.jsp" />
</decorators>
其中
blank.jsp页面代码如下:
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!DOCTYPE html>
<html style="overflow-x:auto;overflow-y:auto;">
<head>
<title><sitemesh:title/></title><!-- - Powered By JeeSite -->
<%@include file="/static/include/head.jsp" %>
<sitemesh:head/>
</head>
<body>
<sitemesh:body/>
</body>
</html>
default.jsp代码如下:
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!DOCTYPE html>
<html style="overflow-x:auto;overflow-y:auto;">
<head>
<title><sitemesh:title/></title>
<%@include file="/static/include/head.jsp" %>
<sitemesh:head/>
</head>
<body id="<sitemesh:getProperty property='body.id'/>" class="<sitemesh:getProperty property='body.class'/>" style="<sitemesh:getProperty property='body.style'/>">
<sitemesh:body/>
<script type="text/javascript">//<!-- 无框架时,左上角显示菜单图标按钮。
if(!(self.frameElement && self.frameElement.tagName=="IFRAME")){
$("body").prepend("<i id=\"btnMenu\" class=\"icon-th-list\" style=\"cursor:pointer;float:right;margin:10px;\"></i><div id=\"menuContent\"></div>");
$("#btnMenu").click(function(){
top.layer.open({
type: 2,
area:['300px','350px'],
content: 'get:${ctx}/sys/menu/treeselect;JSESSIONID=<shiro:principal property="sessionid"/>' //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com', 'no']
});
//top.$.jBox('get:${ctx}/sys/menu/treeselect;JSESSIONID=<shiro:principal property="sessionid"/>', {title:'选择菜单', buttons:{'关闭':true}, width:300, height: 350, top:10});
//if ($("#menuContent").html()==""){$.get("${ctx}/sys/menu/treeselect", function(data){$("#menuContent").html(data);});}else{$("#menuContent").toggle(100);}
});
}//-->
</script>
</body>
</html>
其中<%@include file=”/static/include/head.jsp” %>中的head.jsp页面就是所有js或者css公用引用的页面,例如:
<%@ page contentType="text/html;charset=UTF-8" %><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><meta name="author" content="http://www.jeeplus.org/"/>
<meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=9,IE=10" />
<meta http-equiv="Expires" content="0"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Cache-Control" content="no-store">
<!-- 引入jquery插件 -->
<script src="${ctxStatic}/jquery/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/jquery/jquery-migrate-1.1.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctxStatic}/TableDnD/jquery.tablednd.js"></script>
<!-- 引入依赖的第三方插件 -->
<script src="${ctxStatic}/slimscroll/jquery.slimscroll.min.js"></script>
<script src="${ctxStatic}/jquery-validation/1.14.0/jquery.validate.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/jquery-validation/1.14.0/localization/messages_zh.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/jquery-validation/1.14.0/additional-methods.min.js" type="text/javascript"></script>
<link href="${ctxStatic}/jquery-jbox/2.3/Skins/Bootstrap/jbox.min.css" rel="stylesheet" />
<script src="${ctxStatic}/jquery-jbox/2.3/jquery.jBox-2.3.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/pace/pace.min.js"></script>
<script src="${ctxStatic}/metisMenu/jquery.metisMenu.js"></script>
......
以上是decorators.xml主要配置文件,根据这个配置文件的注释可以看出,需要在每一个需要引用公共js或者css的地方添加注释的一行代码,如下:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp"%>
<html>
<head>
<title>通知管理</title>
<!-- 这一行代码是重点 -->
<meta name="decorator" content="default"/>
</head>
<body class="gray-bg">
其中content=“default”中的“default”对应“decorators.xml”配置文件中的“ name”属性值。
通过上面的配置,在加载完的页面,点击右键查看源代码可以看到加载完页面会出现head.jsp页面的代码。
[转]decorators.xml的用法的更多相关文章
- 转-decorators.xml的用法-http://blog.csdn.net/gavinloo/article/details/7458062
今天改前人做的项目,用struts2,spring,hibernate框架做的,对了,还有jQuery.我用jquery做异步请求到后台,生成json数据返回前台生成下拉输入框,请求到后台以后,成功生 ...
- decorators.xml的用法 (转)
spring,hibernate框架做的,对了,还有jQuery. 我用jquery做异步请求到后台,生成json数据返回前台生成下拉输入框,请求到后台以后,成功生成了json数据并根据struts的 ...
- decorators.xml的用法
spring,hibernate框架做的,对了,还有jQuery.我用jquery做异步请求到后台,生成json数据返回前台生成下拉输入框,请求到后台以后,成功生成了json数据并根据struts的映 ...
- SQL FOR XML PATH 用法
FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作.那么以一个实例为主 ...
- 装饰页面decorators.xml
WEB-INF/decorators.xml 这个配置可以增加页面的 装饰页面
- 一个由正则表达式引发的血案 vs2017使用rdlc实现批量打印 vs2017使用rdlc [asp.net core 源码分析] 01 - Session SignalR sql for xml path用法 MemCahe C# 操作Excel图形——绘制、读取、隐藏、删除图形 IOC,DIP,DI,IoC容器
1. 血案由来 近期我在为Lazada卖家中心做一个自助注册的项目,其中的shop name校验规则较为复杂,要求:1. 英文字母大小写2. 数字3. 越南文4. 一些特殊字符,如“&”,“- ...
- 使用Spring Mvc 转发 带着模板 父页面 之解决方法 decorators.xml
周末了,周一布置的任务还没完毕,卡在了页面跳转上,接手了一个半截的项目要进行开发,之前没有人给培训.全靠自己爬代码,所以进度比較慢.并且加上之前没实用过 Spring Mvc 开发项目.所以有点吃力, ...
- mssql sqlserver for xml EXPLICIT 用法详解说明
摘要:下文通过举例的方式,详细说明"for xml EXPLICIT"关键字的用法,如下所示:实验环境:sql server 2008 R2 EXPLICIT的功能:将数据表采用特 ...
- sql 将某列转换成一个字符串 for xml path用法
declare @test table( name varchar(10)) insert into @test values('a') insert into @test values('b') i ...
随机推荐
- Ubantu17.10 上安装gitlab
http://www.jianshu.com/p/92f97939e33a 亲测成功
- Ubuntu环境中的Android源代码下载
跟随“老罗的Android之旅”学习Android系统,首先得学会创建能用于编译Android源代码的环境. 文章参考:http://0xcc0xcd.com/p/books/978-7-121-18 ...
- DJI-A2调参详细教程
DJI-A2飞控系统用户手册 https://wenku.baidu.com/view/bb632f88227916888586d749.html DJI-A2调参软件视频教程 http://www. ...
- [ZJOI2013]K大数查询
Description: 给定一个序列,支持两种操作 1.在[L,R]的每个位置上加上一个数 (注意一个位置上有多个数) 2.查询[L,R]上所有数中的第K大 Hint: \(n,m<=5e4\ ...
- C++程序设计方法3:虚函数
向上映射与向下映射 派生类对象转换成基类对象,称为向上映射. 而基类对象转换成派生类对象,称为向下映射: 向上映射可由编译器自动完成,是一种隐式的自动类型转化: 凡是接受基类对象的地方(如函数参数)都 ...
- Tyrion 中文文档(含示例源码)
原文出处: Mr.Seven Tyrion是一个基于Python实现的支持多个WEB框架的Form表单验证组件,其完美的支持Tornado.Django.Flask.Bottle Web框架.Ty ...
- pycharm实现sublime的显示效果,很惊艳哦
收到https://github.com/simoncos/pycharm-monokai链接中的指引 下载箭头所指的文件,然后按照 PyCharm -> File -> Settings ...
- 移动端适配问题px->rem方法
移动端web页面适配问题 1.引入插件 github地址:https://github.com/re54k/mobileweb-utilities/blob/master/util/mobile-ut ...
- 28、初识socket(subprocess模块)
经过近一个半月的学习我们已经度过了python基础的阶段,今天我们开始学习python网络编程,没有难以理解的逻辑,更注重的是记忆. 本篇导航: 客户端/服务器架构 scoket与网络协议 套接字 基 ...
- 通过Nginx反向代理之后客户端验证码session不一致造成无法验证通过的问题解决
location / { proxy_pass http://127.0.0.1:9080/app/; proxy_cookie_path /app/ /; proxy_cookie_path /ap ...