数据加载中……
sitemesh 简单入门
2008年4月16日  edited by dingdangxiaoma
引用
sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。
sitemesh 是OpenSymphony 组织下的子项目。
准备:从官方下载 sitemesh包拷贝到你项目下的lib下。
web.xml 添加以下内容。
    <filter>
        
<filter-name>sitemesh</filter-name>
        
<filter-class>
            com.opensymphony.module.sitemesh.filter.PageFilter  //这是个过滤器。
        
</filter-class>
    
</filter>

    
<filter-mapping>
        
<filter-name>sitemesh</filter-name>
        
<url-pattern>/*</url-pattern>
    </filter-mapping>
WEB-INF 下建立decorators.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
    
<decorator name="main" page="main.jsp">      <!--装饰页面-->
        
<pattern>*</pattern>       <!-- 装饰映射-->
    
</decorator>
</decorators>
在webroot 下新建:decorators/main.jsp
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
    prefix
="decorator"%>
<html>
    
<head>
        
<title>
<decorator:title default="decorators" />
        
</title>
        
<decorator:head />
    
</head>
    
<body>
        sitemesh的例子
        
<hr>
        
<decorator:body />
        
<hr>
        DingDangXiaoMa@
163.com 
    
</body>
</html>
建立 index.jsp
<%@ page contentType="text/html; charset=GBK"%>
<html>
     
<head>
       
<title>343</title>
     
</head>
     
<body>
       
<p>本页只有一句,就是本句.</p>
     
</body>
</html>
当通过访问服务器时:http://localhost/sitemesh/index.jsp时。
会看到:
sitemesh的例子
本页只有一句,就是本句.
DingDangXiaoMa@
163.com
这就输出结果了。访问的结果自动装载上了main.jsp样式。这就是添加了sitemesh 过滤的结果。
这就是一个简单的例子,只是说明了整个问题的应用,而没有涉及到各个细节问题。
当然,sitemesh 还有很多内容。支持的视图不公包含了.jsp还有velocity freemarker等。
参考资料:
http://www.java3z.com/cwbwebhome/article/article2/2962.html?id=1668
http://www.cjsdn.net/post/view?bid=29&id=178862

posted on 2008-04-16 11:13 叮当小马 阅读(270) 评论(0)  编辑  收藏 所属分类: OpenSymphony


只有注册用户登录后才能发表评论。


网站导航: