<!-- sitemesh filter--> <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>
<?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/WEB-INF/jsp/decorators"> <!--main decorator--> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator> <!--<excludes>--> <!--<pattern>/index.jsp*</pattern>--> <!--</excludes>--> </decorators>4.编写WEB-INF/jsp/decorators下的main.jsp文件,内容举例:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="keywords" content="bookstore, theme, free template, nivo image slider, website, templatemo, CSS, HTML" /> <meta name="description" content="sc.chinaz.com from templatemo.com" /> <link href="${pageContext.request.contextPath}/css/templatemo_style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/ddsmoothmenu.css" /> <script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/script/ddsmoothmenu.js"> /*********************************************** * Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ </script> <script type="text/javascript"> ddsmoothmenu.init({ mainmenuid: "templatemo_menu", //menu DIV id orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" classname: 'ddsmoothmenu', //class added to menu's outer DIV //customtheme: ["#1c5a80", "#18374a"], contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] }); </script> <link rel="stylesheet" type="text/css" media="all" href="${pageContext.request.contextPath}/css/jquery.dualSlider.0.2.css" /> <script src="${pageContext.request.contextPath}/script/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/script/jquery.easing.1.3.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/script/jquery.timers-1.2.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/script/jquery.dualSlider.0.3.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#carousel").dualSlider({ auto:true, autoDelay: 6000, easingCarousel: "swing", easingDetails: "easeOutBack", durationCarousel: 1000, durationDetails: 600 }); }); </script> <script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery-1-4-2.min.js"></script> <link rel="stylesheet" href="${pageContext.request.contextPath}/css/slimbox2.css" type="text/css" media="screen" /> <script type="text/JavaScript" src="${pageContext.request.contextPath}/script/slimbox2.js"></script> <title><decorator:title default=""/> -- MaoJun Yang</title> <decorator:head/> </head> <body> <div> <!-- 相当于head.jsp --> <div><a href="${pageContext.request.contextPath}/login.jsp">登录</a> <a href="${pageContext.request.contextPath}/register.jsp">注册</a></div> <div id="templatemo_header_wrapper"> <div id="templatemo_header"> <div id="site_title"><a href="http://sc.chinaz.com/">Free CSS Templates</a></div> <div id="templatemo_menu" class="ddsmoothmenu"> <ul> <li><a href="${pageContext.request.contextPath}/index.jsp" class="selected">首页</a></li> <li><a href="${pageContext.request.contextPath}/about.jsp">关于</a> <ul> <li><span class="top"></span><span class="bottom"></span></li> <li><a href="http://sc.chinaz.com/">图书</a></li> </ul> </li> <li><a href="${pageContext.request.contextPath}/portfolio.jsp">图书列表</a> <ul> <li><span class="top"></span><span class="bottom"></span></li> <li><a href="http://sc.chinaz.com/">图书</a></li> </ul> </li> <li><a href="${pageContext.request.contextPath}/blog.jsp">感言</a></li> <li><a href="${pageContext.request.contextPath}/contact.jsp">购物车</a></li> </ul> <br style="clear: left" /> </div> <!-- end of templatemo_menu --> <div class="clear"></div> <!-- 此处是整个WEB目录下的其他jsp页面body插入的位置 --> <decorator:body/> </div> </div> </div> <div> <!-- 此处相当于foot.jsp,当然其他页面不用写其他代码也能有这个foot.jsp --> <div id="templatemo_footer_wrapper"> <div id="templatemo_footer"> <div class="col one_fourth"> <h4>Photo Gallery</h4> <ul class="footer_gallery"> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_03_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_03.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_04_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_04.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_05_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_05.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_06_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_06.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_07_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_07.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_08_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_08.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_09_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_09.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_10_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_10.jpg" alt="image" /></a></li> <li><a href="${pageContext.request.contextPath}/images/templatemo_image_11_l.jpg" rel="lightbox[portfolio]"><img src="${pageContext.request.contextPath}/images/templatemo_image_11.jpg" alt="image" /></a></li> </ul> <div class="clear"></div> <a href="portfolio.jsp" class="more">更多</a> </div> <div class="col one_fourth"> <h4>最近</h4> <ul class="no_bullet"> <li> <span class="header"><a href="#"></a></span> </li> <li> <span class="header"><a href="#">Ipsum dolor sit amet</a></span> . </li> <li> <span class="header"><a href="#">吖吖</a></span> 做大大大大双刀地飞 </li> </ul> </div> <div class="col one_fourth"> <h4>Twitter</h4> <ul class="no_bullet"> <li><a href="#">@templatemo</a> </li> <li>联系 <a href="#">#FREE</a> </li> <li> <a href="#">http://bit.ly/13IwZO</a></li> <li> <a href="#">http://bit.ly/IyyUoO</a></li> </ul> </div> <div class="col one_fourth no_margin_right"> <h4>About</h4> <p> 版权归属<a href="#">Your Company Name</a> | Collect from <a href="http://www.cssmoban.com/" title="网站模板" target="_blank">网站模板</a> </div> <div class="clear"></div> </div> <!-- END of footer --> </div> <!-- END of footer wrapper --> </div> </body> </html>5.这个main.jsp只是个例子而已,其中必须要定义那个前缀:decorator,然后才能使用<decorator:title default=""/>、<decorator:head/>、<decorator:body/>等等。之后的话,只要是在整个web根目录下的jsp都会被这个SitMesh所装饰。
版权声明:本文为博主原创文章,未经博主允许不得转载。