- 浏览: 780222 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (386)
- Linux (36)
- Tomcat (6)
- windows (8)
- Apache (10)
- Java (25)
- jquery (7)
- Jquery 插件 (3)
- Oracle (5)
- Oracle SQL (68)
- Spring (15)
- 开发工具 (6)
- Struts (20)
- js (14)
- Project Code (2)
- Project Code Tomcat (1)
- libset (1)
- JSP (8)
- arithmetic (2)
- 浏览器 (1)
- extjs (3)
- 学习网站 (5)
- 生活情感 (0)
- 电话号码算法 (3)
- 快捷键 (1)
- 转载 (1)
- Dos命令 (2)
- services (1)
- Resources (1)
- 行业积累 (3)
- 项目积累 (3)
- Web (3)
- 文档 (1)
- JavaEE (2)
- JSF (3)
- http (3)
- JS窗口 (1)
- Html (4)
- Flex (1)
- 资讯 (2)
- 项目规范 (1)
- Struts s:property textarea中默认值用 (1)
- Quartz 2.0.2 (12)
- 1天有多少毫秒 (1)
- 专题 (1)
- intellij idea 10 CD-KEY (1)
- restlet (4)
- Mail (1)
- Excel (3)
- Menu (1)
- Big Data技术综述 (1)
- Quart 1 (1)
- nosql (1)
- linux远程 (1)
- jdk (5)
- wind7 (1)
- 虚拟人 (0)
- 虚拟机 (1)
- 终端 (1)
- Ubuntu (16)
- Myeclipse (2)
- Wmware (1)
- eclipse (2)
- css (2)
- csv (1)
- 开源 (1)
- plsql (2)
- cassandra (4)
- maven (1)
- hadoop (2)
- mysql (1)
- spring security (1)
- tools (1)
- jdbc (2)
- exception (2)
- 硬盘数据备份 (1)
- dwr (1)
- svn (1)
- PowerDesigner15使用时的十五个问题 (1)
- tomcat 项目发部路径 (1)
- js 暂停执行 (1)
- jquery jqgrid 格式化数据显示 (1)
- js 代码模板 (1)
- strutss2 直接跳转到jsp页面 (1)
- servlet (1)
- jdbc spring (1)
- js学习网站 (1)
- 自学考试 (2)
- hibernate (2)
- eos (1)
- c (4)
- 黑马 (2)
- 大数据 (2)
- 实战云大数据案例分享 (0)
- Spark (2)
- Flink (1)
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
jquery button 漂亮 -
thinktothings:
Array_06 写道你好,我是一名刚毕业学生,我以后就是做J ...
如何转型架构师 -
thinktothings:
软考,考有职业资格证,有系统的知识体系学习
如何转型架构师 -
Array_06:
你好,我是一名刚毕业学生,我以后就是做Java的架构师,那请问 ...
如何转型架构师 -
beykery:
你这也太复杂了。。。。jsf2不应该是这样的。。。。
JSF2.0的一个简单Demo
http://www.sitemesh.org/
Getting started with SiteMesh3
Introduction
This tutorial is a quick introduction to using SiteMesh3 in a web-application. It covers:
- A high level overview of how SiteMesh3 works
- Installation and configuration
- Building and applying a simple decorator
It is recommend you read the high level SiteMesh Overview before this tutorial.
SiteMesh in web applications
In a web application, SiteMesh acts as a Servler Filter. It allows requests to be handled by the Servlet engine as normal, but the resulting HTML (referred to as the content ) will be intercepted before being returned to the browser.
The intercepted content has certain properties extracted (typically the contents of the
<title>
, <head>
and <body>
tags and is then passed on to a
second request that should return the common look and feel for the site (referred to as the decorator
). The decorator
contains placeholders for where the properties extracted from the content should be inserted.
Under the hood, a key component of the SiteMesh architecture is the content processor . This is an efficient engine for transforming and extracting content from HTML content. For most users, it's fine to use it as it comes, but it is also possible to define your own transformation and extraction rules.
SiteMesh does not care what technologies are used to generate the content or the decorator. They may be static files, Servlet, JSPs, other filters, MVC frameworks, etc. So long as it's served by the Servlet engine, SiteMesh can work with it.
Dependencies
Running SiteMesh3 requires at least:
- JDK 1.5
- A Servlet 2.5 compliant container
- The SiteMesh runtime library
The SiteMesh library should be downloaded
and placed in /WEB-INF/lib/
.
Setup
Insert the SiteMesh Filter in /WEB-INF/web.xml
:
<web-app> ... <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> </web-app>
Deploy the web-application to your Servlet container. From this point onwards, this tutorial assumes the web-app is running at http://myserver/
.
Creating a decorator
The decorator
contains the common layout and style that should be applied to the pages in the web application.
It is a template that contains place holders for the content's <title>
, <head>
and
<body>
elements.
At the bear minimum, it should contain:
<html> <head> <title><sitemesh:write property='title'/> </title> <sitemesh:write property='head'/> </head> <body> <sitemesh:write property='body'/> </body> </html>
The <sitemesh:write property='...'/>
tag will be rewritten by SiteMesh to include properties extracted from
the content. There are more properties that can be extracted from
the content and it's possible to define your own rules - that will
be covered in another tutorial.
The bear minimum decorator isn't very useful. Let's add some style and a bit of common layout.
Create the file /decorator.html
in your web-app, containing:
<html> <head> <title>SiteMesh example: <sitemesh:write property='title'/> </title> <style type='text/css'> /* Some CSS */ body { font-family: arial, sans-serif; background-color: #ffffcc; } h1, h2, h3, h4 { text-align: center; background-color: #ccffcc; border-top: 1px solid #66ff66; } .mainBody { padding: 10px; border: 1px solid #555555; } .disclaimer { text-align: center; border-top: 1px solid #cccccc; margin-top: 40px; color: #666666; font-size: smaller; } </style> <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>
In this example, the decorator is a static .html
file, but if you want the decorator to be more dynamic, technologies such as JSP, FreeMarker, etc can be used.
SiteMesh doesn't care - it just needs a path that can be served content by the Servlet engine.
Configuration
SiteMesh needs to be configured to know about this decorator and what it should do with it.
The configuration file should be created at /WEB-INF/sitemesh3.xml
:
<sitemesh> <mapping path="/* " decorator="/decorator.html "/> </sitemesh>
This tells SiteMesh that requests matching the path /*
(i.e. all requests) should be decorated with /decorator.html
that we just created.
If you don't like the idea of having to use XML to configure SiteMesh, don't worry - there are alternative mechanisms including
directly in WEB-INF/web.xml
, programatically through a Java API, through Spring, by naming convention, or any custom way you may choose to plug in.
These are explained further in another article
.
Creating some content
Now to create some content. This is defined in plain HTML content. Create /hello.html
:
<html> <head> <title>Hello World </title> <meta name='description' content='A simple page'> </head> <body> <p>Hello <strong>world</strong>!</p> </body> </html>
Like the decorator, the content may be static files or dynamically generated by the Servlet engine (e.g. JSP).
The result
Pointing your browser to http://myserver/hello.html
will serve the content you just created, with the
decorator applied. The resulting merged HTML will look like this:
<html> <head> <title>SiteMesh example: Hello World </title> <style type='text/css'> /* Some CSS */ body { font-family: arial, sans-serif; background-color: #ffffcc; } h1, h2, h3, h4 { text-align: center; background-color: #ccffcc; border-top: 1px solid #66ff66; } .mainBody { padding: 10px; border: 1px solid #555555; } .disclaimer { text-align: center; border-top: 1px solid #cccccc; margin-top: 40px; color: #666666; font-size: smaller; } </style> <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>
As you can see, the <title>
, <head>
and <body>
have
been extracted from the content and inserted into the decorator template.
Summary
A quick recap:
- SiteMesh is installed by dropping the library jar in
/WEB-INF/lib
and creating a filter (with mapping) in/WEB-INF/web.xml
- It can be configured by creating a
/WEB-INF/sitemesh3.xml
file, or through other configuration methods - The filter intercepts requests to Content , runs it through the Content Processor and merges with a Decorator
- The Content is defined by an HTML page, that contains the vanilla HTML content of the site
- The Decorator
is also defined by an HTML page, that contains the look and feel of the site, and placeholder
<sitemesh:write>
tags to indicate where the Content should be merged in - The Content Processor contains the rules for extracting and transforming the content - it has some simple default rules and can be customized
====================================================================
其实就只有这一点点就可以用了
====================================================================
SiteMesh example site: Hello World
Well hello there, fine world.
And so concludes this SiteMesh example.
How it works
- This page (
/index.html
) contains vanilla HTML content. - SiteMesh is configured (in
/WEB-INF/web.xml
) to apply a decorator to all paths (/*
). - The decorator (
/decorator.html
) contains the common look and feel that is applied to the site.
- sitemesh-3.0-alpha-2.zip (962.6 KB)
- 下载次数: 3
- sitemesh-examples-hellowebapp-3.0-alpha-2.war (123 KB)
- 下载次数: 1
- sitemesh-examples-hellowebapp-3.0-alpha-2.zip (124.2 KB)
- 下载次数: 6
相关推荐
【sitemesh3-demo】是一个基于Sitemesh3框架的示例项目,旨在展示如何在Web应用程序中有效地实现页面布局和装饰功能。Sitemesh是一个开源的Java Web应用框架,主要用于增强网页的外观和结构,通过定义装饰模板,可以...
除了基本的装饰器配置之外,还可以对`sitemesh3.xml`进行更细致的配置: - **支持多种MIME类型**: ```xml <mime-type>text/html</mime-type> <mime-type>application/vnd.wap.xhtml+xml <mime-type>application...
**Sitemesh3** 是一个开源的网页布局和装饰框架,用于Java Web应用程序。它主要目的是帮助开发者统一网站的外观和感觉,通过提供一种简单的方式来装饰(或模板化)整个Web应用中的页面。Sitemesh3是Sitemesh项目的第...
**SpringMVC、Freemarker与Sitemesh3详解** SpringMVC是Spring框架的一部分,它是一个用于构建Web应用程序的模型-视图-控制器(MVC)架构。SpringMVC提供了一个灵活的处理机制,包括处理器映射、视图解析、数据绑定...
**Sitemesh3 SDK详解** Sitemesh 是一个开源的 Web 应用程序框架,用于增强网站的布局和装饰功能。Sitemesh3 是其第三个主要版本,它提供了更现代的架构和更好的性能,旨在帮助开发者更高效地管理和美化他们的网页...
springmvc + mybatis + sitemesh3 超简洁例子 整合springmvc mybatis 方法请看: http://blog.csdn.net/kokoyuo/article/details/52808510
在本项目中,我们探索的是一个基于Spring MVC、MyBatis和Sitemesh3的超简洁登录示例,其中还集成了MySQL数据库和MD5加密验证。这是一个经典的Java Web开发框架组合,常用于构建高效、可扩展的企业级应用。下面我们将...
##### 3. 配置装饰器 - 创建装饰器配置文件`[web-app]/WEB-INF/decorators.xml`。 - 文件结构示例: ```xml <!-- 在这里定义装饰器 --> ``` ##### 4. 可选配置 - 创建可选配置文件`[web-app]/WEB-INF/...
3. **负载测试**:模拟不同并发用户数量,观察系统的响应时间。 **实验结果** - 在低并发情况下,使用SiteMesh对性能影响不大。 - 随着并发用户数的增加,使用SiteMesh的应用程序响应时间略有提升,但整体仍然稳定...
3. **模块化**:易于添加、修改和重用页面组件。 4. **可扩展性**:支持与其他模板引擎集成,适应各种开发需求。 然而,Sitemesh也有其局限性,例如对于JavaScript驱动的单页应用(SPA)支持不够理想,因为它主要是...
标题:Sitemesh技术的应用 描述与标签:Sitemesh技术的应用 Sitemesh技术是Web开发领域中一种用于页面装饰的重要工具,尤其在Java Web应用程序中被广泛应用。其核心功能在于能够统一网站的外观风格,使不同功能...
`sitemesh3demo附配置说明`这个主题涉及到的是一个使用Sitemesh3框架的演示项目,其中包含了配置的详细指南。Sitemesh是一个开源的Web应用程序模板引擎和页面装饰框架,它主要用来帮助开发者实现网页布局、样式统一...
3. **定义装饰模板**:SiteMesh允许你创建一个或多个装饰模板,这些模板定义了页面的结构,如页眉、页脚、侧边栏等。你可以使用HTML或者JSP来编写模板。 4. **应用装饰**:通过在JSP页面中使用特殊的注解(例如`<@...
Java Sitemesh是一个开源的页面布局和装饰框架,它的主要目标是帮助开发者统一网站的外观和感觉,提高代码复用性,并简化页面的复杂性。Sitemesh通过将页面分为内容区域和装饰模板来实现这一目标,使得开发者可以...
3. **配置SiteMesh**: 在`sitemesh.xml`中指定布局文件的位置和装饰策略。 4. **标记页面内容**: 在需要装饰的JSP或HTML页面中添加特殊的SiteMesh注释或标签,告知SiteMesh如何插入到布局文件中。 5. **运行应用**...
Sitemesh是一款强大的Web页面布局和装饰框架,它主要用于帮助开发者实现网站的统一外观和感觉。这个框架的主要功能是将页面的主体内容与页眉、页脚、侧边栏等通用部分分离,使得在大量网页中保持一致的设计风格变得...
3. **创建装饰模板**:Sitemesh使用HTML文件作为装饰模板,你可以根据需求创建一个基础模板,例如`layout.html`,该模板通常包含页头、页脚、侧边栏等公共部分。 4. **设置页面内容**:对于每个需要装饰的页面,...
- **核心组件**:Grails 的核心架构基于三个成熟的 Java 开源框架:**Spring**、**Hibernate** 和 **SiteMesh**。 - **Spring**:用于管理应用程序的依赖注入和服务层逻辑。 - **Hibernate**:提供对象关系映射 ...
3. 如果需要,Sitemesh会先执行原始JSP或Servlet,获取内容页面的HTML输出。 4. 接着,Sitemesh会将这个内容插入到预先定义好的装饰模板中,这个模板定义了页面的整体结构,如头部、底部、侧边栏等。 5. 最后,...