加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

decorators.xml

发布时间:2020-12-16 00:26:13 所属栏目:百科 来源:网络整理
导读:要使用decorator标签需要下载sitemesh.jar包. decorator标签可以轻松解决页面布局的问题,轻松是因为相比include标签(需要在每个页面都用他引入JSP)而言,decorator标签的使用很简便,只需要在配置文件decorators.xml进行相应的配置再加上一个装饰器(其实就是一
要使用decorator标签需要下载sitemesh.jar包.
decorator标签可以轻松解决页面布局的问题,轻松是因为相比<include>标签(需要在每个页面都用他引入JSP)而言,decorator标签的使用很简便,只需要在配置文件decorators.xml进行相应的配置再加上一个装饰器(其实就是一个JSP页面)即可.
decorators.xml
<decorators defaultdir="/decorators">
<excludes>
<pattern>/shared/*</pattern>
</excludes>
<decorator name="style" page="style.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>

<excludes> 标签代表不对定义的请求名进行装饰
<decorator> 标签代表对定义的请求名进行相应的装饰
现在我门需要定义一个style.jsp文件,官方是称之为装饰器,俺觉得称他是模版文件更贴切
style.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<html>
<head>
<title><decorator:title default="装饰器页面..." /></title>
<decorator:head />
</head>
<body>
<p><font color="red">this is style's header</font></p>
<hr>
<decorator:body />
<p><font color="red">this is style's footer</font></p>
</body>
</html>
需要注意的是style.jsp需要放在 根目录/decorators目录下面,当然decorators目录是需要自己建的.
在这个JSP里面,我们要用到decorator标签了,注意在用之前别忘了定义标签:
至于<decorator:title>,<decorator:head />,<decorator:body />的作用,后面再说!
然后要作的就是准备好我们访问的页面
index.jsp:
<head>
<title>decorator-index.jsp</title>
</head>
<body>
this is index.jsp. it's a simple page.
</body>
把这个页面放在 根目录下和 根目录/shared目录下面一份
现在把应用运行起来
访问:
http://localhost:8080/testDecorator/index.jsp
http://localhost:8080/testDecorator/shared/index.jsp
看看两个页面有什么不一样的?
没错,第一个链接看到的页面还包含style.jsp的东东.
而第二个链接却没有,是因为在decorators.xml文件在把这类的请求给过滤了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读