sitemesh的使用步驟

sitemesh的使用步驟:
1.添加 Library File:將sitemesh-xxxx.jar導入到WEB-INF/lib中。
2.添加 SiteMesh Filter:配置WEB-INF/web.xml文件,將下面的配置加入到web.xml文件中的web-app標籤中。

<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>

3.創建模板文件:basic-theme.jsp

<?xml version="1.0" encoding="UTF-8" ?>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <h1>Header</h1>
    <p><b>Navigation</b></p>
    <hr />
    <decorator:body />
    <hr />
    <h1>Footer</b></h1>
</body>
</html>

4.將裝飾器的模板文件page和其匹配的模式pattern關聯起來:創建一個名爲decorator.xml文件在WEB-INF/下。內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
    <decorator name="basic-theme" page="basic-theme.jsp">
        <pattern>/data/*</pattern>
    </decorator>
</decorators>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章