`
zhchx0827
  • 浏览: 192091 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

sitemesh初体验

 
阅读更多
1:新建Web project
2:添加架包:struts2.2.3  +   sitemesh3.0
           commons-fileupload-1.2.2.jar
           commons-io-2.0.1.jar
           commons-lang-2.5.jar
           freemarker-2.3.16.jar
           javassist-3.11.0.GA.jar
           ognl-3.0.1.jar
           struts2-core-2.2.3.jar
           xwork-core-2.2.3.jar
           sitemesh-3.0-alpha-2.jar

3:web.xml配置(和struts2.0.1有点不同)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts Blank</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

<!-- 配置struts2 -->
    <!-- <filter>
    <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
   </filter>
 
  <filter-mapping>
    <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping> -->
 
  <!-- 配置sitemesh -->
  <!-- <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> -->

<filter>
    <filter-name>struts-cleanup</filter-name>
    <filter-class>
   org.apache.struts2.dispatcher.ActionContextCleanUp
  </filter-class>
  </filter>
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>
   org.sitemesh.config.ConfigurableSiteMeshFilter
  </filter-class>
  </filter>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
   org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


</web-app>

3:编写struts.xml文件

4:WEB-INF下新建sitemesh3.xml文件
<sitemesh>
  <mapping path="/*" decorator="/templator/decorator.html"/>
</sitemesh>

5:WebRoot包下建立templator文件夹,下面建立decorator.html文件
<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>

6:部署到tomcat上,访问路径http://localhost:8080/struts/即可

在此没有编写任何的action,仅仅测试sitemesh的helloword的配置
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics