sitemesh使用

在WEB-INF--lib下導入sitemesh的jar包

wKioL1UmMteB_pokAAGD0XEUfso332.jpg

web.xml中添加如下代碼

  1. <!-- sitemesh -->
      <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>

新建decorators.xml 表示該樣式作用於哪些JSP頁面

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
<decorator name="banner" page="banner.jsp">
<pattern>/jsp/*</pattern><!--jsp目錄-->
</decorator>
</decorators>

公共樣式就在webroot下的decorators文件下面

如banner.jsp

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<div id="templatemo_menu">
    <ul>
            <li><a href="home.jsp" class="current">Home</a></li>
            <li><a href="showAll" class="current">Review</a></li>
            <li><a href="write.jsp" class="current">Write Review</a></li>
            <li><a href="list" class="current">Book</a></li>
            <li><a href="us.jsp" class="current">About Us</a></li>
            <li><a href="show.jsp" class="current">show bookq</a></li>
        </ul>
    </div>
    </div><!-- end of container --> 
    
    <decorator:body />
    
    <div id="templatemo_container">
    <div id="templatemo_footer">

這樣其他的JSP頁面就可以運用公共樣式了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章