打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
页面布局(sitemesh)
1、介绍
SiteMesh是一个网页的布局和装饰框架和Web应用集成框架,以帮助创建网站组成的页面,一个一致的外观/感觉,导航和布局方案的要求。SiteMesh拦截请求任何静态或动态生成的HTML页面的请求通过Web服务器,处理内容然后将它与一个或多个装饰打造的最终结果。SiteMesh可将小页面及层组装成大页;SiteMesh很快。真的很快。SiteMesh可以用在基于Web的应用程序的java,或应用内容的脱机工作。SiteMesh是可扩展的。
2、架构图
 

3、案例
 3.1、集成

     3.1.1、引入相关jar

     3.1.2、配置web.xml

<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

3.2、定义装饰器(decorator)

   3.2.1、创建页面(decorator.htmlor jsp/freemaker

<html>
  <head>
    <title>SiteMesh example: 
<sitemesh:write property='title'/></title>
    
<sitemesh:write property='head'/>
  </head>
  <body>

<h1 class='title'>

SiteMesh example site: <sitemesh:write property='title'/>

</h1>

<div class='mainBody'>
    
<sitemesh:write property='body'/>
</div>

<div class='disclaimer'>Site disclaimer. This is an example.</div>

  </body>
</html>

    3.2.2、创建配置(sitemesh3.xml)

<sitemesh>
  <mapping path="/*" decorator="/decorator.html"/>
</sitemesh>

3.3、定义内容页

<html>
  <head>
    <title>Hello World</title>
    <meta name='description' content='A simple page'>
  </head>
  <body>
    <p>Hello <strong>world</strong>!</p>
  </body>
</html>

3.4、最终输出效果

<html>
  <head>
    <title>SiteMesh example: 
Hello World</title>
   
 <meta name='description' content='A simple page'>
  </head>
  <body>

<h1 class='title'>SiteMesh example site: Hello World</h1>

<div class='mainBody'>

<p>Hello <strong>world</strong>!</p>

</div>

<div class='disclaimer'>Site disclaimer. This is an example.</div>

</body>
</html>


4、配置说明
<sitemesh>
  <!-- Map default decorator. This shall be applied to all paths if no other paths match. -->
  <mapping decorator="/default-decorator.html"/>
 <!-- Map decorators to path patterns. -->
  <mapping path="/admin/*" decorator="/another-decorator.html"/>
  <mapping path="/*.special.jsp" decorator="/special-decorator.html"/>
 <!-- Alternative convention. This is more verbose but allows multiple decorators to be applied to a single path. -->
  <mapping>
    <path>/articles/*</path>
    <decorator>/decorators/article.html</decorator>
    <decorator>/decorators/two-page-layout.html</decorator>
    <decorator>/decorators/common.html</decorator>
  </mapping>
  <!-- Exclude path from decoration. -->
  <mapping path="/javadoc/*" exclue="true"/>
  <mapping path="/brochures/*" exclue="true"/>
  <!--This can be altered to allow SiteMesh to intercept responses for other types. This is only applicable for the SiteMesh Filter - it is ignored by the offline site builder-->
  <mime-type>text/html</mime-type>
  <mime-type>application/vnd.wap.xhtml+xml</mime-type>
  <mime-type>application/xhtml+xml</mime-type>
</sitemesh>

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Introduction to SiteMesh
SiteMesh
filter
使用SiteMesh简化网页布局
sitemesh性能测试结果比较惊艳(已经补上新的对比测试结果)
Java Web Web应用,打包和web.xml文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服