SiteMesh参考

SiteMesh参考

作者:kongxx (kongxx@gmail.com)

安装

  • 首先从sitemesh下载安装包,这里使用的是2.2.1版本。
  • 创建一个Web应用程序,这里我创建一个名为myapp的Web应用程序;
  • 复制sitemesh-2.2.1.jar文件到{myapp}/WEB-INF/lib目录下;
  • 编辑{myapp}/WEB-INF/web.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<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>

<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>

添加蓝色高亮部分。
  • 在{myapp}/WEB-INF/目录下创建decorators.xml文件,并且输入一下内容
<?xml version="1.0" encoding="ISO-8859-1"?>

<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>

<decorator name="panel" page="panel.jsp"/>
<decorator name="printable" page="printable.jsp"/>
</decorators>
  • 安装完毕。

例子1

  • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
<decorator name="mydecorator1" page="mydecorator1.jsp">
<pattern>/test1.jsp</pattern>
</decorator>
  • 在{myapp}/decorators目录下添加mydecorator1.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<html>
<head>
<title>My Site - <decorator:title default="Welcome!" /></title>
<decorator:head />
</head>
<body>
<decorator:body />
<p>This message is in /decorators/mydecorator1.jsp</p>
</body>
</html>
  • 在{myapp}目录下添加test1.jsp文件,内容如下:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is test1</title>
</head>
<body>
<b>This is test1</b>
</body>
</html>

  • 打开浏览器,访问http://localhost:8080/myapp/test1.jsp,将会出现一下内容:

This is test1

This message is in /decorators/mydecorator1.jsp


例子2 (decorator:getProperty tag)

有时候,我们期望修改页面中某个有固定标记的片段,例如我们的jsp中有一个标记<mytag>...</mytag>,此时可以用如下方法实现:
  • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
<decorator name="mydecorator2" page="mydecorator2.jsp">
<pattern>/test2.jsp</pattern>
</decorator>
  • 在{myapp}/decorators目录下添加mydecorator2.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>

<html>
<head>
<title>My Site - <decorator:title default="Welcome!" /></title>
<decorator:head />
</head>

<body>
<decorator:body />

<decorator:getProperty property="page.content1"/>
<decorator:getProperty property="page.content2"/>

<!-- do nothing -->
<decorator:getProperty property="page.content3"/>

<p>This message is in /decorators/mydecorator2.jsp</p>
</body>
</html>
  • 在{myapp}目录下添加test2.jsp文件,内容如下:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is test2</title>
</head>

<body>
<b>This is test2</b>
<b>Use &lt;decorator:getProperty&gt; tag</b>

<content tag="content1"><p>This is content1</p></content>
<content tag="content2"><p>This is content2</p></content>
<content tag="content4"><p>This is content4, it shouldn't be display</p></content>
</body>
</html>
  • 打开浏览器,访问http://localhost:8080/myapp/test2.jsp,将会出现一下内容:

This is test2

Use <decorator:getProperty> tag

This is content1

This is content2

This message is in /decorators/mydecorator2.jsp

例子3 (page:applyDecorator tag)

  • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
<decorator name="mydecorator3" page="mydecorator3.jsp">
<pattern>/test3.jsp</pattern>
</decorator>

<decorator name="mydecorator31" page="mydecorator31.jsp">
</decorator>
  • 在{myapp}/decorators目录下添加mydecorator3.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>
<html>
<head>
<title>My Site - <decorator:title default="Welcome!" /></title>
<decorator:head />
</head>

<body>
<decorator:body />

<page:applyDecorator name="mydecorator31">
<content tag="content1"><p>This is content1</p></content>
<content tag="content2"><p>This is content2</p></content>
</page:applyDecorator>
</body>
</html>
在{myapp}/decorators目录下添加mydecorator31.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

<p><i>begin</i></>
<decorator:getProperty property="page.content1"/>
<decorator:getProperty property="page.content2"/>
<p><i>end</i></>
  • 在{myapp}目录下添加test3.jsp文件,内容如下:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is test3</title>
</head>

<body>
<b>This is test3</b>
<b>Use &lt;page:applyDecorator&gt; tag</b>
</body>
</html>
注意:相对于例子2,这里已经没有了<content tag="XXX"/>标签。
  • 打开浏览器,访问http://localhost:8080/myapp/test3.jsp,将会出现一下内容:

This is test3

Use <page:applyDecorator> tag

begin

This is content1

This is content2

end

这里,我在mydecorator3.jsp中应用了mydecorator31.jsp的的decorator,并且将原来在test2.jsp中的 <content />标签复制到mydecorator3.jsp中,此时对于<content tag="xxx"/>的标签将会由mydecorator31.jsp了装饰。

例子4 (page:param tag)

  • 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator
<decorator name="mydecorator4" page="mydecorator4.jsp">
<pattern>/test4.jsp</pattern>
</decorator>

<decorator name="mydecorator41" page="mydecorator41.jsp">
</decorator>
  • 在{myapp}/decorators目录下添加mydecorator4.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

<html>
<head>
<title>My Site - <decorator:title default="Welcome!" /></title>
<decorator:head />
</head>

<body>
<decorator:body />
<page:applyDecorator name="mydecorator41" >
<content tag="content1"><p>This is content1</p></content>
<content tag="content2"><p>This is content2</p></content>
<page:param name="page.content1"><p>This content1 has been replaced</p></page:param>
</page:applyDecorator>
</body>
</html>
在{myapp}/decorators目录下添加mydecorator41.jsp文件,内容如下:
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>

<p><i>begin</i></>
<decorator:getProperty property="page.content1"/>
<decorator:getProperty property="page.content2"/>
<p><i>end</i></>
  • 在{myapp}目录下添加test4.jsp文件,内容如下:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is test4</title>
</head>

<body>
<b>This is test4</b>
<b>Use &lt;page:param&gt; tag</b>
</body>
</html>
  • 打开浏览器,访问http://localhost:8080/myapp/test4.jsp,将会出现一下内容:

This is test4

Use <page:param> tag

begin

This content1 has been replaced

This is content2

end

这里,我在mydecorator4.jsp中应用了mydecorator41.jsp的的decorator,并且添加了 <page:param name="page.content1">标签,那么此时页面上将会用<page:param>标签中的内容替换原来在 <decorator:getProperty property="page.content1"/> 中的内容,因此页面将不在 This is content1” 而显示 This content1 has been replaced ”。
MangaMeeya 是一款在日本很有名气的电子漫画阅览工具,具有速度流畅、操作灵活、书籍管理便捷等优点,并支持多种流行的图像插件,使其功能得到了非常自由的扩展。 图片读取和显示的速度极快是本软件最大的优点,而且作者一直在朝着这个方向努力。本软件复杂的运用了预读技术,您只要以正常速度阅读,图片再大也不会感到丝毫延迟。对于非常大的图片压缩包,无论再快的 CPU 也得数秒钟时间载入,这时您只要选择边载入边阅读,就可以做到一秒钟也不用浪费了。而且在读取完成之后,短时间内再次读取本压缩包将不再花任何时间。在预读功能之外,本软件的读取速度也异常优秀。如果图片大小正常,像实体书那样只用几秒钟时间从头翻到尾的事也能轻松做到。 ·如何以最快的速度浏览:关闭“工具”下拉菜单内的“启用翻页效果”、“启用Avisynth滤镜”,打开“预读文件”、“预读所有文件”。 ·如何实现边载入边阅读:在读取很大的压缩包时,“正在列出文件”对话框会自动出现,点击该对话框内的“在后台列出(按储存顺序)”即可。 本软件可以使用纯鼠标、纯键盘、纯手柄操作,当然也可以混合操作。所有功能的按键都可以自定义,所以绝对不会碰到操作不顺手的情况。和键盘一样,鼠标和手柄也有多键组合功能,不用担心按钮不够用。鼠标中还有一个非常有用的功能——鼠标手势(见本段尾的介绍)。鼠标手势的好处是在程序的操作上完全解放了眼睛,以前必须用眼睛确定菜单项的位置、窗口内按钮的位置、键盘按键的位置,现在则再也不用了,只要像写字一样划上几笔,就可以完成大量复杂的操作,这期间眼睛完全不用离开阅读的内容。 ·如何自定义操作设置:所有的操作设置都在“工具”下拉菜单内的“操作设置”子菜单内。 ·手柄如何进行组合按钮设置:每个按钮对应的功能在手柄对话框内设置,默认按钮5为“自定义控制键”,即组合键。“自定义控制键”与其他按钮组合后的功能也在同一窗口内设置。 ·如何使用鼠标手势:默认设置是以右键拖拽激发鼠标手势功能,只要在主窗口内按住右键拖拽出大致的走向,就会激发该走向对应的功能。比如默认向上拖拽是切换全屏幕,按住右键向上拖拽然后放开,程序就由窗口切换为全屏了,再次向上拖拽的话,就恢复到窗口状态。在“鼠标设置-手势设置”窗口内可以自定义拖拽走向对应的命令,在左边的方框中可以进行可视模拟操作。 不管对于电子书还是实体书来说书签(也就是书籍的管理)都非常重要,本软件设立了一个专门的主菜单项用作书籍的管理,可见其重视程度。在单个书籍(文件夹或压缩包)内部的管理上,程序设有中断点一个(关闭书籍时程序自动设置),记号一个(手动设置用),书目无数个(手动设置用)。程序可以在开启某个书籍时自动转到中断点或记号处,以便继续上次阅读。书目上可以写上简短文字,为书籍分出章节,当然作为普通的书签用也行。在书籍与书籍之间的管理上,程序设有四个列表:播放列表(当前阅读的书籍)、历史(之前阅读过的书籍)、收藏夹(文字式的仓库)、书架(带图片的仓库)。您还可以把任意列表保存为其他文件,等需要时再载入,这样就不用担心列表不够用了。 ·怎样设定打开书籍时转到上次关闭处:“工具-环境设置-一般设置1”内,选中“从中断处开启”。 ·怎样编辑书目:打开书目列表的快捷键默认为“鼠标手势-左”。编辑书目的操作和在 Windows 下修改文件名一样。 ·书架的使用:在列表内的该书籍项目上点击右键,选择“加入封底”。调好“加入位置”(纵坐标)和“加入宽度”后确定,该图块就连同文件信息一起被加入书架中。要显示图片式的书架请选择“查看-显示书架”。“加入封面”后不会显示在书架内,但可以在封面缩略图中看到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值