sitemesh 2.4 装饰器学习
这里值得一提的是,SiteMesh只会把最终生成的html填充到装饰的页面,至于关于之前拦截到需要被装饰的jsp里面引入了一些c标签什么的都不会自动引入到装饰页面的,因为sitemesh只会把最终生成的html加入到装饰页面!!所以这里就造成了几个问题
1.装饰的页面如果要用到通用的非静态资源(jstl标签,page),由于服务器是直接跳转到被装饰页面,然后处理jstl等成为普通html才把被装饰页面加入到装饰页面,所以在被装饰页面引入的一些非静态资源是不会加入到装饰页面的,装饰页面还要在引一片通用的 tag,也就是jstl标签。结果就是被装饰页面和装饰页面引tag(也就是非静态资源)都要引两遍
使用sitemesh的步骤
1. 添加jar文件到classpath
maven地址
<dependency><groupId>opensymphony</groupId><artifactId>sitemesh</artifactId><version>2.4.2</version></dependency>
2. 在web.xml中增加过滤器
<!-- Sitemesh --><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>/*</url-pattern></filter-mapping>
3. 在/WEB-INF中创建decorators.xml文件
<?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/layouts/"><!-- 不需要过滤的请求 --><excludes><pattern>/static/*</pattern><pattern>/remote/*</pattern></excludes><!-- 定义装饰器要过滤的页面 --><decorator name="default" page="default.jsp"><pattern>/*</pattern></decorator></decorators>
默认页面default.jsp:
<%@ page contentType="text/html;charset=UTF-8"%><%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><html><head><title>SiteMesh示例-<sitemesh:title/></title><sitemesh:head/></head><body><%@ include file="/layouts/header.jsp"%><div id="content"><sitemesh:body/></div><%@ include file="/layouts/footer.jsp"%></body></html>
简单说明:
- 引入了SiteMesh标签。
- <sitemesh:title/> 会自动替换为被过滤页面的title。
- <sitemesh:head/> 会把被过滤页面head里面的东西(除了title)放在这个地方。
- <sitemesh:body/> 被过滤的页面body里面的内容放在这里。
- 头部引入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://jeesite.com/"/><meta name="renderer" content="webkit"><meta http-equiv="X-UA-Compatible" content="IE=8,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"><script src="${ctxStatic}/jquery/jquery-1.8.3.min.js" type="text/javascript"></script><link href="${ctxStatic}/bootstrap/2.3.1/css_${not empty cookie.theme.value ? cookie.theme.value : 'cerulean'}/bootstrap.min.css" type="text/css" rel="stylesheet" /><script src="${ctxStatic}/bootstrap/2.3.1/js/bootstrap.min.js" type="text/javascript"></script><link href="${ctxStatic}/bootstrap/2.3.1/awesome/font-awesome.min.css" type="text/css" rel="stylesheet" /><!--[if lte IE 7]><link href="${ctxStatic}/bootstrap/2.3.1/awesome/font-awesome-ie7.min.css" type="text/css" rel="stylesheet" /><![endif]--><!--[if lte IE 6]><link href="${ctxStatic}/bootstrap/bsie/css/bootstrap-ie6.min.css" type="text/css" rel="stylesheet" /><script src="${ctxStatic}/bootstrap/bsie/js/bootstrap-ie.min.js" type="text/javascript"></script><![endif]--><link href="${ctxStatic}/jquery-select2/3.4/select2.min.css" rel="stylesheet" /><script src="${ctxStatic}/jquery-select2/3.4/select2.min.js" type="text/javascript"></script><link href="${ctxStatic}/jquery-validation/1.11.0/jquery.validate.min.css" type="text/css" rel="stylesheet" /><script src="${ctxStatic}/jquery-validation/1.11.0/jquery.validate.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}/My97DatePicker/WdatePicker.js" type="text/javascript"></script><script src="${ctxStatic}/common/mustache.min.js" type="text/javascript"></script><link href="${ctxStatic}/common/jeesite.css" type="text/css" rel="stylesheet" /><script src="${ctxStatic}/common/jeesite.js" type="text/javascript"></script><script type="text/javascript">var ctx = '${ctx}', ctxStatic='${ctxStatic}';</script>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>有人拦截我吗?</title></head><body>有人拦截我吗?</body></html>
sitemesh 2.4 装饰器学习的更多相关文章
- Python 装饰器学习
Python装饰器学习(九步入门) 这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方式. 第一步:最简单的函数,准备附加额外功能 1 2 3 4 5 6 7 8 # -*- c ...
- (转载)Python装饰器学习
转载出处:http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html 这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方 ...
- Python装饰器学习
Python装饰器学习(九步入门) 这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方式. 第一步:最简单的函数,准备附加额外功能 ? 1 2 3 4 5 6 7 8 # -*- ...
- Python装饰器学习(九步入门)
这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方式. 第一步:最简单的函数,准备附加额外功能 ? 1 2 3 4 5 6 7 8 # -*- coding:gbk -*- '''示 ...
- Python 装饰器学习心得
最近打算重新开始记录自己的学习过程,于是就捡起被自己废弃了一年多的博客.这篇学习笔记主要是记录近来看的有关Python装饰器的东西. 0. 什么是装饰器? 本质上来说,装饰器其实就是一个特殊功能的函数 ...
- python装饰器学习详解-函数部分
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 最近阅读<流畅的python>看见其用函数写装饰器部分写的很好,想写一些自己的读书笔记. ...
- python 装饰器学习(decorator)
最近看到有个装饰器的例子,没看懂, #!/usr/bin/python class decorator(object): def __init__(self,f): print "initi ...
- Python 装饰器学习以及实际使用场景实践
前言 前几天在看Flask框架,对于非常神奇的@语法,不是非常的理解,回来补装饰器的功课.阅读很多的关于装饰器的文章,自己整理一下,适合自己的思路的方法和例子,与大家分享. app = Flask(_ ...
- python装饰器学习笔记
定义:本质上就是个函数,(装饰器其他函数)就是为了给其他函数添加附加功能 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 #-*-coding:utf-8-*- 1 imp ...
随机推荐
- 16、Xtrabackup备份与恢复
XTRABACKUP xtrabackup是percona公司开发的第三方备份软件,只备份innodb引擎表的ibd文件(frm不备份),不备份myisam引擎表.备份性能很高,备份期间没有任和锁,d ...
- RawCap抓取本地回环接口数据包
RawCap.exe --help ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 D: ...
- ab并发负载压力测试
一.ab 0.安装ab压力测试软件 [root@a2 conf]# yum install httpd-tools -y #查看版本 [root@a2 conf]# ab -V This is Apa ...
- Hibernate原生SQL查询数据转换为HQL查询数据方法
HQL形式:(构造方法不支持timestamp类型) public List<Device> queryByMatherBoardId(String matherBoardId) { St ...
- 登录Tomcat控制台
在http://localhost:8080界面中,右上角有三个按纽对应着三个控制台:Server Status控制台,Manager App控制台和Host Manager控制台.Server St ...
- FastDFS安装配置过程中出现错误提示"/home/yuqing/fastdfs" can't be accessed, error info: No such file or directory
解决: mkdir -p /home/yuqing/fastdfs 这回正常了,查看启动成功与否 [root@localhost FastDHT]# ps -ef |grep track |grep ...
- Textarea自动适用高度且无滚动条解决方案
今日的系统需要动态显示一项数据库里面的内容,该内容包含换行等格式字符,要求如实的反应在页面上. 最初解决办法是使用textarea控件,代码如下: <textarea style="b ...
- Redis 数据结构之简单动态字符串SDS
几个概念1:key对象 数据库存储键值对的键,总是一个字符串对象.2:value对象 数据库存储键值对的值,可以是字符串对象,list对象,hash对象,set对象,sorted set对象. ...
- 算法笔记_052:蓝桥杯练习Multithreading(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 现有如下一个算法: repeat ni times yi := y y := yi+1 end repeat 令n[1]为你需要算加法的第 ...
- WebDriver API——第4部分Alerts
The Alert implementation. class selenium.webdriver.common.alert.Alert(driver) Bases: object Allows t ...