使用decorator模式对jsp页面布局

[size=medium]使用decorator模式对jsp页面进行布局:

步骤:

1.web.xml:

<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


2.新建decorator.xml文件 配置需布局对象与不需要布局对象:
<?xml version="1.0" encoding="UTF-8"?>

<decorators defaultdir="/WEB-INF/views/decorators">

<!-- 不需要布局的页面 -->

<excludes>

<pattern>/login</pattern>

<pattern>/uploadImage/**</pattern>

<pattern>/category/preview1/**</pattern>

<pattern>/category/previewNews</pattern>

<pattern>/category/preview/preview/**</pattern>

</excludes>

<!-- 布局的页面 -->
<decorator page="/WEB-INF/views/decorators/decorator.jsp" name="header">
<!-- 对所有符合/category,/pass,/account,/activity 请求路劲的uri jsp页面进行页面布局-->
<pattern>/pass</pattern>

<pattern>/category/**</pattern>

<pattern>/account/**</pattern>
<pattern>/activity/**</pattern>
</decorator>

</decorators>

3.新建decorator.jsp

<?xml version="1.0" encoding="UTF-8" ?>
<%@ include file="../taglibs.jsp"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!DOCTYPE html>
<!--[if IE 8]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 wp-toolbar" lang="zh-CN">
<![endif]-->
<!--[if !(IE 8) ]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar" lang="zh-CN">
<!--<![endif]-->
<head>
<title><decorator:title /></title>
<decorator:head />
</head>
<body class="wp-admin wp-core-ui js users-php auto-fold admin-bar branch-3-6 version-3-6 admin-color-fresh locale-zh-cn customize-support">
<div id="wpwrap">
<%@ include file="../menu.jsp"%><!--左边菜单栏-->
<div id="wpcontent">
<%@ include file="../nav.jsp"%><!--头部-->
<decorator:body /><!--主体部分-->
<div class="clear"></div>
</div>
</div>
</body>
</html>


[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值