??xml version="1.0" encoding="utf-8" standalone="yes"?>国产乱码精品1区2区3区,日本一区二区在线不卡,四虎8848精品成人免费网站http://www.aygfsteel.com/shiwenfeng/category/42429.html在不断模ѝ思考、ȝ中一步一步进步!zh-cnWed, 28 Oct 2009 09:19:45 GMTWed, 28 Oct 2009 09:19:45 GMT60Struts2和SiteMesh整合之web.xmlhttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300084.htmlshiwfshiwfWed, 28 Oct 2009 09:11:00 GMThttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300084.htmlhttp://www.aygfsteel.com/shiwenfeng/comments/300084.htmlhttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300084.html#Feedback0http://www.aygfsteel.com/shiwenfeng/comments/commentRss/300084.htmlhttp://www.aygfsteel.com/shiwenfeng/services/trackbacks/300084.html<?xml version="1.0" encoding="GBK"?>
<!-- 配置Web应用配置文g的根元素Qƈ指定配置文g的Schema信息 -->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
 <!-- 定义ActionContextCleanUpqo?-->
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
 </filter>
 <!-- 定义SiteMesh的核心过滤器 -->
 <filter>
  <filter-name>sitemesh</filter-name>
  <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
 </filter>
 <!-- 定义Struts 2的核心过滤器 -->
 <filter>
  <filter-name>struts</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>

 <!-- 定义qo器链 -->
 <!-- 排在W一位的qo器是QActionContextCleanUpqo?-->
 <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 排在W二位的qo器是QSiteMesh的核心过滤器 -->
 <filter-mapping>
  <filter-name>sitemesh</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 排在W三位的qo器是QFilterDispatcherqo?-->
 <filter-mapping>
  <filter-name>struts</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <!-- 定义一个ListenerQ该Listener在应用启动时创徏Spring容器 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <!-- 定义一个ListenerQ该Listener在应用启动时加蝲MyFaces的Context -->
 <listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener
  </listener-class>
 </listener>
 <!-- 配置JSF的FacesServletQ让其在应用启动时加?-->
 <servlet>
  <servlet-name>faces</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <!-- 让FacesServlet拦截所有以*.actionl尾的请?-->
 <servlet-mapping>
  <servlet-name>faces</servlet-name>
  <url-pattern>*.action</url-pattern>
 </servlet-mapping>
</web-app>



shiwf 2009-10-28 17:11 发表评论
]]>
sitemesh技术的应用http://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300045.htmlshiwfshiwfWed, 28 Oct 2009 05:47:00 GMThttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300045.htmlhttp://www.aygfsteel.com/shiwenfeng/comments/300045.htmlhttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/28/300045.html#Feedback0http://www.aygfsteel.com/shiwenfeng/comments/commentRss/300045.htmlhttp://www.aygfsteel.com/shiwenfeng/services/trackbacks/300045.html一、基本概?/div>
1、Sitemesh是一U页面装饰技?Q?/div>
1  Q它通过qo?filter)来拦截页面访?br /> 2  Q根据被讉K面的URL扑ֈ合适的装饰模板
3  Q?strong>提取被访问页面的内容Q放到装饰模板中合适的位置
4  Q最l将装饰后的面发送给客户端?img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" />
2、在sitemesh中,面分ؓ两种Q装饰模板和普通页面?br /> 1Q装饰模板,是指用于修饰其它面的页面?br /> 2Q普通页面,一般指各种应用面?/div>
二、模板修饰网늚原理







通过Sitemesh的注册机Ӟ告诉SitemeshQ当讉K该\径时使用XXX模板Q假定用前面那个模板)来修饰被讉K面?



当用户在左边D栏点?#8220;戏说长城”Q?/ShowGreatWall.doQ时Q右边的“戏说长城”面会被指定的模板修饰



ȝ上面q程QSitemesh修饰|页的基本原理,可以通过下面来说明:



三、Sitemesh的配|与使用
1QWEB-INF/web.xml中加入filter定义与sitemesh的taglib定义
     <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>

     <taglib>
          <taglib-uri>sitemesh-decorator</taglib-uri>
          <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
     </taglib>
     <taglib>
          <taglib-uri>sitemesh-page</taglib-uri>
          <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
     </taglib> 
2Q创建WEB-INF/decorators.xmlQ在该文件中配置有哪些模板,以及每个模板具体修饰哪些URLQ另外也可以配置哪些URL不需要模板控?, decorators.xml的一个例子如下:
<excludes>
<pattern>/Login*</pattern>
</excludes>

<decorators defaultdir="/decorators">
    
<decorator name="main" page=“DecoratorMainPage.jsp">
        
<pattern>/*</pattern> 
    
</decorator>

    
<decorator name=“pop" page=“PopPage.jsp">
        
<pattern>/showinfo.jsp*</pattern>
        
<pattern>
              /myModule/GreatWallDetailAction.do*
        
</pattern>
    
</decorator>
</decorators>
3Q我们看一个修饰模板的例子
<%@page contentType="text/html;?charset=GBK"%>
<%@taglib uri="sitemesh-decorator"?prefix="decorator" %>

<html>
    
<head>
         
<title> <decorator:title/> </title>
         
<decorator:head/>
    
</head>

    
<body>
        Hello World  
<hr/>
        
<decorator:body/>
    
</body>
</html> 
4Q我们看一个被修饰的页面的例子Q?/div>
<%@ page contentType="text/html;?charset=GBK"%>
<html>
    
<head>
        
<title>Hello World</title>
    
</head>

    
<body>
        
<p>Decorated page goes here.</p
    </body
>
</html> 
5Q我们看一下装饰模板中可以使用的Sitemesh标签 
<decorator:head />
 取出被装饰页面的head标签中的内容?
<decorator:body />
取出被装饰页面的body标签中的内容?
<decorator:title default=""  />
取出被装饰页面的title标签中的内容。default为默认?/div>
<decorator:getProperty property="" default=""  writeEntireProperty=""/>
取出被装饰页面相x{属性倹{?
writeEntireProperty表明Q是昄属性的D是显C?#8220;属??#8221;
Html标签的属?br /> Body标签的属?br /> Meta标签的属?/div>
注意如果其contentg包含“>?/span><”会报错,需转码Q例?amp;lt;{等
default是默认?/div>
<decorator:usePage id="" />
 被装饰面构造ؓ一个对象,可以在装饰页面的JSP中直接引?/strong>?
6Q看一个在装饰模板中用标{例子
<html lang=“ <decorator:getProperty property=‘lang’/> ”>
    
<head>
        
<title> <decorator:title default=“你好” /> </title>
        
<decorator:head />
    
</head>
    
    
<body <decorator:getProperty property=“body.onload" writeEntireProperty=“1"/> >
         
从meta中获取变量company的名Uͼ
             <decorator:getProperty property
=“meta.company”/>

            
下面是被修饰面的body中的内容Q?br />              <decorator:body />

         
<decorator:usePage id=“myPage" />

         
<%=myPage.getRequest().getAttribute(“username”)%>
    
</body>
</html>
7Q看一下相应的在被修饰面中的代码Q?/div>
<html lang=“en”>
    
<head>
        
<title>我的sitemesh</title>
        
<meta name=“company” content=“smartdot”/>
        
<meta name=“Author” content=“zhangsan”/>
        
<script>
             function count(){return 10;}
        
</script>
    
</head>

    
<body onload=“count()”>
         
<p>q是一个被修饰面</p>
    
</body>
</html>
四、ȝ

1QSitemesh最为重要的是做用于修饰的模板Qƈ在decorators.xml中配|这些模板用于修饰哪些页面。因此用Sitemesh的主要过E就是:做装饰模?/u>Q然?u>在decorators.xml中配|URL Pattern

2Q分析整个工E,看哪些页面需要抽象成模板Q例如二U页面、三U页面、弹出窗口等{可能都需要做成相应的模板Q一般来_一个大型的OApȝQ模板不会超q?个?br />
如果某个Ҏ的需求请求\径在qo器的范围内,但又不想使用模板怎么办?
你M能这么不讲道理吧Q?br />         大家攑ֿ吧,SiteMesh早就考虑到这一点了Q上面第5步说道的decorators.xmlq个时候就起到作用了!
下面是我的decorators.xmlQ?/div>
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
    <!-- Any urls that are excluded will never be decorated by Sitemesh -->
    <excludes>
        <pattern>/index.jsp*</pattern>
          <pattern>/login/*</pattern>
    </excludes>
    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>
 decorators.xml有两个主要的l点Q?br />       decoratorl点指定了模板的位置和文件名Q通过pattern来指定哪些\径引用哪个模?br />       excludesl点则指定了哪些路径的请求不使用M模板
如上面代码,/index.jsp和凡是以/login/开头的h路径一律不使用模板Q?/div>
另外q有一点要注意的是Qdecoratorsl点的defaultdir属性指定了模板文g存放的目?


shiwf 2009-10-28 13:47 发表评论
]]>初识SiteMeshhttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/27/299925.htmlshiwfshiwfTue, 27 Oct 2009 07:47:00 GMThttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/27/299925.htmlhttp://www.aygfsteel.com/shiwenfeng/comments/299925.htmlhttp://www.aygfsteel.com/shiwenfeng/archive/2009/10/27/299925.html#Feedback0http://www.aygfsteel.com/shiwenfeng/comments/commentRss/299925.htmlhttp://www.aygfsteel.com/shiwenfeng/services/trackbacks/299925.html一、SiteMesh目?Q?/span>http://www.opensymphony.com/sitemesh/ Q?br />       OS(OpenSymphony)的SiteMesh是一个用来在JSP中实现页面布局和装饎ͼlayout and decorationQ的框架lgQ能够帮助网站开发h员较Ҏ实现面中动态内容和静态装饰外观的分离?br />
       Sitemesh是由一个基于Web面布局、装C及与现存Web应用整合的框架。它能帮助我们在由大
量页面构成的目中创Z致的面布局和外观,如一致的D条,一致的bannerQ一致的版权Q等{?
它不仅仅能处理动态的内容Q如jspQphpQasp{生的内容Q它也能处理静态的内容Q如htm的内容,
使得它的内容也符合你的页面结构的要求。甚至于它能HTML文g象include那样该文g作ؓ一个面?
的Ş式嵌入到别的文g中去。所有的q些Q都是GOF的Decorator模式的最生动的实现。尽它是由java语言来实现的Q但它能与其他Web应用很好地集成?nbsp;
      官方Q?/span>
http://www.opensymphony.com/sitemesh/ 
      下蝲地址Q?/span>http://www.opensymphony.com/sitemesh/download.action 目前的最新版本是Version 2.3Q?

二、ؓ什么要使用SiteMesh? 
    我们的团队开发J2EE应用的时候,l常会碰C个比较头疼的问题Q由于Web面是由不同的h所开发,所以开发出来的界面通常是千奇百怪,通常让项目管理h员苦W不得。而实际上QQ何一个项目都会要求界面的l一风格和美观,既然风格l一Q那p明UI层肯定有很多可以抽出来共用的静态或动态部分;如何整合q些通用的静态或动态UI呢?Apache Tiles框架站了出来很好的解决了q一问题Q再加上他与struts的完集成,D大小目都把他作为UI层的首选框Ӟ但是QTiles实有着它很多的不之处,下文我会介绍,本文惌的是Q除了Apache Tiles框架,其实我们q有更好的解 x案,那就?SiteMeshQ?br />     本文介绍了一个基于Web面的布局、装C及应用整合的框架SitemeshQ它能帮助你Z的应用创Z致的外观Q很好的取代Apache Tiles;

三、SiteMesh VS Apache Tiles 
     用过struts的朋友应该对Apache Tiles的不会陌生,我曾l有一文章介l过struts中tiles框架的组合与l承Q现在怎么看怎么觉得复杂
       从用角度来看,Tilesg是Sitemesh标签<page:applyDecorator>的一个翻版。其实sitemesh最强的一个特性是sitemeshdecorator模式用在qo器上。Q何需要被装饰的页面都不知道它要被谁装饎ͼ所以它可以用来装璜来自php、asp、CGI{生的面了。你可以定义若干个装饰器Q根据参数动态地选择装饰器,产生动态的外观以满你的需求。它也有一套功能强大的属性体p,它能帮助你构建功能强大而灵zȝ装饰器。相比较而言Q在q方面Tiles逊色许多?nbsp;
     个h觉得在团队开发里面,Apache Tiles框架会导致所有h不仅仅要了解q且清楚Apache Tiles的存在,q且要特别熟悉每一个Tiles layout模板的作用,否则可能出现用错模板的情况Q除此之外,每个人涉及到的所有WEB面都需要去配置文g里面逐个配置Q不仅麻烦出错的几率q高Q而以上所有的不都是SiteMesh所不存在的?

四、SiteMesh的基本原?nbsp;
      一个请求到服务器后Q如果该h需要sitemesh装饰Q服务器先解释被h的资源,然后Ҏ配置文g
获得用于该请求的装饰器,最后用装饰器装饰被h资源Q将l果一同返回给客户端浏览器?

五、如何用SiteMesh 
       q里以struts2+spring2+hibernate3构架的系lؓ?nbsp;
          1、下载SiteMesh 
              下蝲地址Qhttp://www.opensymphony.com/sitemesh/download.action 目前的最新版本是Version 2.3Q?nbsp;      
           2、在工程中引入SiteMesh的必要jar包,和struts2-sitemesh-plugin-2.0.8.jarQ?nbsp;      
           3、修改你的web.xml,在里面加入sitemesh的过滤器Q示例代码如下:
        
<!-- sitemesh配置 -->
    <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> 
         注意qo器的位置Q应该在struts2的org.apache.struts2.dispatcher.FilterDispatcherqo器之前org.apache.struts2.dispatcher.ActionContextCleanUpqo器之后,否则会有问题Q?

       4、在下蝲的SiteMesh包中扑ֈsitemesh.xmlQ?\sitemesh-2.3\src\example-webapp\WEB-INF目录下就?
        其拯?WEB-INF目录下;

       5、在sitemesh.xml文g中有一个propertyl点(如下)Q该l点指定了decorators.xml在工E中的位|?让sitemesh.xml能找C; 按照此\径新建decorators.xml文gQ当然这个\径你可以L改变Q只要propertyl点的valueg其匹配就行; 
    <property name="decorators-file" value="/WEB-INF/sitemesh/decorators.xml"/> 
    
      6、在WebRoot目录下新建decorators目录Qƈ在该目录下新Z个模板jspQ根据具体项目风格编辑该模板Q?br />             如下CZQ我的模板:main.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="decorator"
     uri="http://www.opensymphony.com/sitemesh/decorator"%>
<%@taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
     response.setHeader("Pragma", "no-cache");
     response.setHeader("Cache-Control", "no-cache");
     response.setDateHeader("Expires", 0);
%>
<html>
    <head>
        <title><decorator:title default="kangxm test" />
        </title>
        <!-- 面Head由引用模板的子页面来替换 -->
        <decorator:head />
    </head>
    <body id="page-home">
        <div id="page-total">
            <div id="page-header">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>
                            <div class="topFunc">
                                 我的账户
                                 |
                                 退?
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!-- end header -->
        <!--   Menu Tag begin -->
        <div id="page-menu" style="margin-top: 8px; margin-bottom: 8px;">
            <div>
                 q里放菜?
            </div>
        </div>
        <!--   Menu Tag end -->
        <div id="page-content" class="clearfix">
            <center>
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <decorator:body /><!-- q里的内容由引用模板的子面来替?-->
                        </td>
                    </tr>
                </table>
            </center>
        </div>
        <!-- end content -->
        <div id="page-footer" class="clearfix">

             q里N面底?
            <!-- end footer -->
        </div>
        <!-- end page -->
    </body>
</html>


q就是个单的模板Q页面的头和脚都由模杉K的静态HTML军_了,主页面区域用的是<decorator:body />标签Q也是说凡是能q入qo器的h生成的页面都会默认加上模板上的头和脚Q然后页面自w的内容自动放?lt;decorator:body />标签所在位|;
<decorator:title default="Welcome to test sitemesh!" />Q读取被装饰面的标题,q给Z默认标题?
<decorator:head />Q读取被装饰面?lt;head>中的内容Q?
<decorator:body />Q读取被装饰面?lt;body>中的内容Q?

      7、说到这里大家就要想了,那如果某个特D的需求请求\径在qo器的范围内,但又不想使用模板怎么办? 你M能这么不讲道理吧Q大家放心吧QSiteMesh早就考虑到这一点了Q上面第5步说道的decorators.xmlq个时候就起到作用了!
       
下面是我的decorators.xmlQ?
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
    <!-- Any urls that are excluded will never be decorated by Sitemesh -->
    <excludes>
        <pattern>/index.jsp*</pattern>
          <pattern>/login/*</pattern>
    </excludes>
    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

decorators.xml有两个主要的l点Q?
       decoratorl点指定了模板的位置和文件名Q通过pattern来指定哪些\径引用哪个模?
       excludesl点则指定了哪些路径的请求不使用M模板
如上面代码,/index.jsp和凡是以/login/开头的h路径一律不使用模板Q?
另外q有一点要注意的是Qdecoratorsl点的defaultdir属性指定了模板文g存放的目?

六、实战感?nbsp;
      刚刚做完一个用到sitemesh的项目,跟以前用tiles框架相比Q最大的感受是单,pȝ设计阶段
把模板文g和sitemesh框架搭好了!哪些面使用框架哪些不用,全部都通过UI Demo很快定义出来了Q?
在接下来的开发中所有成员几乎感受不到sitemesh的存在,各自仅仅兛_自己的模块功能实玎ͼ

七、ȝ 
    使用sitemeshl我们带来的是不仅仅是页面结构问题,它的出现让我们有更多的时间去x底层业务
逻辑Q而不是整个页面的风格和结构。它让我们摆׃大量用include方式复用面尬局面,也避免了tiles
框架在团队开发中的复杂度Q它q提供了很大的灵zL以及给我们提供了整合异构Webpȝ面的一U方?


本文来自CSDN博客Q{载请标明出处Qhttp://blog.csdn.net/it_man/archive/2009/01/17/3817347.aspx



shiwf 2009-10-27 15:47 发表评论
]]>
վ֩ģ壺 | | Ϫ| | Դ| ׿| ˮ| | ˷| | ɽ| | | ն| | | Ž| ĵ| ʡ| | | | ¡| | ƽ| ɽ| | | ͳ| ұ| ̨| Ǹ| | | ˮ| żҽ| | | | | ͤ|