decorators.xml配置基础

前端之家收集整理的这篇文章主要介绍了decorators.xml配置基础前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

要使用decorator标签需要下载sitemesh.jar包.

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

输出用户所访问的页面中title,head,body标签之间的内容(不包含<title>,<head>,<body>标签).


原文出自:http://blog.csdn.net/vacblog/article/details/8425183

猜你在找的XML相关文章