上次發表了Sitemesh3 配置教學~
當然~討厭鬼的慣例不是跳舞
再來就是進階配置了
那就開始吧!!!!
討厭鬼在Sitemesh3 配置教學這邊教了一個簡單的simple
現在大部份的人在套版時是不太會把所有的header、menu、footer放在同一個版面
因為如果同一個footer或header要重覆使用的時候
會要再寫一遍,而且要修改的話也要每個地方都要修改
這樣是很奇怪的。
但是~sitemesh是可以允許一次用多個版面
例如
<mapping>
<path>/leather/*</path>
<decorator>/decorator/footer_decorator.jsp</decorator>
<decorator>/decorator/header_decorator.jsp</decorator>
<decorator>/decorator/leather_decorator.jsp</decorator>
</mapping>
不過呢...非常的難用
意思就是說~這樣不能用
要用一次要用多個版面可以改為下列方法
一樣是簡單的宣告
<sitemesh>
<mapping path="/leather/*" decorator="/decorator/leather_decorator.jsp"/>
</sitemesh>
但是leather_decorator.jsp改成下列用include的方式
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../css/leather.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/jquery-ui-1.8.19.custom.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/ui.jqgrid.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../css/ui.multiselect.css" media="screen" />
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.19.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="../js/grid.locale-cn.js"></script>
<title>討厭鬼<sitemesh:write property='title'/></title>
</head>
<body>
<div class="container">
<jsp:include page="header_decorator.jsp"/>
<div class="main">
<sitemesh:write property='body'/>
</div>
<jsp:include page="footer_decorator.jsp"/>
</div>
</body>
</html>
這樣配置的好處就是
1、header_decorator.jsp與footer_decorator.jsp可重覆在別的版面使用
2、要修改header_decorator.jsp與footer_decorator.jsp時只要改一個地方就可以了