<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      SiteMesh3整合SpringMVC+FreeMarker

       

      SiteMesh3文檔 http://wiki.sitemesh.org/wiki/pages/viewpage.action?pageId=1081348

      重新搭建項目偶然發現SiteMesh有了新版本SiteMesh3,本著用新不用舊原則果斷升級,多少遇了點坑,順便記錄下

       

       

       

      SiteMesh3配置

       

      1. 添加maven依賴

        <dependency>
            <groupId>org.sitemesh</groupId>
            <artifactId>sitemesh</artifactId>
            <version>3.0.1</version>
        </dependency>
      2. 添加filter

        在web.xml中添加filter

        <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. 配置servlet

        <servlet-mapping>
            <servlet-name>default</servlet-name>
            <url-pattern>*.ftl</url-pattern>
        </servlet-mapping>
      4. 添加sitemesh配置文件 

        1. 添加配置文件 sitemesh3.xml
          默認配置文件路徑為:/WEB-INF/sitemesh3.xml 

          sitemesh3.xml
          <sitemesh>
              <!--
              By default, SiteMesh will only intercept responses that set the Content-Type HTTP header to text/html
              This can be altered to allow SiteMesh to intercept responses for other types.
              默認 SiteMesh 只對HTTP響應頭中Content-Type為 text/html 的類型進行攔截和裝飾,若需要處理其它mime類型需要自行添加配置
              -->
              <mime-type>text/html</mime-type>
              <!--
              Map default decorator. This shall be applied to all paths if no other paths match.
              配置裝飾器,僅設置decorator參數時表示為默認的裝飾器,當沒有任何路徑被匹配時會使用默認裝飾器裝配
               -->
              <mapping decorator="/WEB-INF/decorators/decorator.ftl"/>
              <!--對不同的路徑指定特定的裝飾器-->
              <!--<mapping path="/admin/*" decorator="/WEB-INF/decorators/admin-decorator.ftl"/>-->
              <!--
              Alternative convention. This is more verbose but allows multiple decorators to be applied to a single path.
              對同一路徑可以同時使用多個裝飾器
              -->
              <mapping>
                  <path>/category/*</path>
                  <decorator>/WEB-INF/decorators/common-decorator.ftl</decorator>
                  <decorator>/WEB-INF/decorators/menu-decorator.ftl</decorator>
                  <decorator>/WEB-INF/decorators/category-decorator.ftl</decorator>
              </mapping>
              <!--
              Exclude path from decoration.
              排除路徑,只需將exclue設置為true即可
              -->
              <mapping path="/static/*" exclue="true"/>
              <!--
              An advanced feature of SiteMesh is the ability to define custom rules that manipulate tags on a page.
              These are classes that implement org.sitemesh.content.tagrules.TagRuleBundle.
              默認SiteMesh僅支持title、head、meta、body等tag,可以自定義tag,實現TagRuleBundle接口即可
              -->
              <content-processor>
                  <tag-rule-bundle class="com.sankuai.shangchao.util.HtmlTagRuleBundle"/>
              </content-processor>
          </sitemesh>

        2. 修改配置文件路徑
          默認配置文件路徑為:/WEB-INF/sitemesh3.xml 若需要修改配置文件路徑需要在filter里配置configFile參數 

          <filter>
              <filter-name>sitemesh</filter-name>
              <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
              <init-param>
                  <param-name>configFile</param-name>
                  <param-value>/WEB-INF/sitemesh3.xml</param-value>
              </init-param>
          </filter>

        3. 自定義tag

          HtmlTagRuleBundle.java
          import org.sitemesh.SiteMeshContext;
          import org.sitemesh.content.ContentProperty;
          import org.sitemesh.content.tagrules.TagRuleBundle;
          import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
          import org.sitemesh.tagprocessor.State;
           
          /**
           * Description: FootTagRuleBundle
           * Author: liuzhao
           * Create: 2015-08-22 09:21
           */
          public class HtmlTagRuleBundle implements TagRuleBundle {
              @Override
              public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
                  defaultState.addRule("foot", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("foot"), false));
              }
           
              @Override
              public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
           
              }
          } 

           


      5. decorator示例

        decorator配置頁面布局layout,對應的tag會被進行裝飾替換

        decorator.ftl
        <!DOCTYPE html>
        <html>
        <head>
            <title>
                <sitemesh:write property="title"/>
            </title>
            <sitemesh:write property='head'/>
        </head>
        <body>
        <h1>啦拉拉,我是賣報的小行家</h1>
        <sitemesh:write property='body'/>
        <sitemesh:write property="foot"/>
        </body>
        </html>
      6. SpringMVC、FreeMarker配置(404問題處理)

        sitemesh3是完全獨立的,不和任何框架進行偶合,因此SpringMVC、FreeMarker配置完全不需要考慮sitemesh3的兼容問題
        在加載裝飾器的時候,會出現404問題,可能的原因是找不到ftl文件的解析器,所以需要配置下ftl使用默認的Servlet解析,在web.xml中添加如下配置

        <servlet-mapping>
            <servlet-name>default</servlet-name>
            <url-pattern>*.ftl</url-pattern>
        </servlet-mapping>

         

      1. decorate源碼

        @Override
        protected boolean postProcess(String contentType, CharBuffer buffer,
                                      HttpServletRequest request, HttpServletResponse response,
                                      ResponseMetaData metaData)
                throws IOException, ServletException {
            WebAppContext context = createContext(contentType, request, response, metaData);
            Content content = contentProcessor.build(buffer, context);
            if (content == null) {
                return false;
            }
         
            String[] decoratorPaths = decoratorSelector.selectDecoratorPaths(content, context);
            //遍歷裝飾器進行裝飾
            for (String decoratorPath : decoratorPaths) {
                content = context.decorate(decoratorPath, content);
            }
         
            if (content == null) {
                return false;
            }
            try {
                content.getData().writeValueTo(response.getWriter());
            catch (IllegalStateException ise) {  // If getOutputStream() has already been called
                content.getData().writeValueTo(new PrintStream(response.getOutputStream()));
            }
            return true;
        }
         
        public Content decorate(String decoratorName, Content content) throws IOException {
            if (decoratorName == null) {
                return null;
            }
         
            class CharBufferWriter extends CharArrayWriter {
                public CharBuffer toCharBuffer() {
                    return CharBuffer.wrap(this.buf, 0this.count);
                }
            }
            CharBufferWriter out = new CharBufferWriter();
            decorate(decoratorName, content, out);
         
            CharBuffer decorated = out.toCharBuffer();
         
            Content lastContent = currentContent;
            currentContent = content;
            try {
                return contentProcessor.build(decorated, this);
            finally {
                currentContent = lastContent;
            }
        }
         
        @Override
        protected void decorate(String decoratorPath, Content content, Writer out) throws IOException {
            HttpServletRequest filterableRequest = new HttpServletRequestFilterable(request);
            // Wrap response so output gets buffered.
            HttpServletResponseBuffer responseBuffer = new HttpServletResponseBuffer(response, metaData, new BasicSelector(new PathMapper<Boolean>(), includeErrorPages) {
                @Override
                public boolean shouldBufferForContentType(String contentType, String mimeType, String encoding) {
                    return true// We know we should buffer.
                }
            });
            responseBuffer.setContentType(response.getContentType()); // Trigger buffering.
         
            // It's possible that this is reentrant, so we need to take a copy
            // of additional request attributes so we can restore them afterwards.
            Object oldContent = request.getAttribute(CONTENT_KEY);
            Object oldContext = request.getAttribute(CONTEXT_KEY);
         
            request.setAttribute(CONTENT_KEY, content);
            request.setAttribute(CONTEXT_KEY, this);
         
            try {
                // Main dispatch.
                dispatch(filterableRequest, responseBuffer, decoratorPath);
         
                // Write out the buffered output.
                CharBuffer buffer = responseBuffer.getBuffer();
                out.append(buffer);
            catch (ServletException e) {
                //noinspection ThrowableInstanceNeverThrown
                throw (IOException) new IOException("Could not dispatch to decorator").initCause(e);
            finally {
                // Restore previous state.
                request.setAttribute(CONTENT_KEY, oldContent);
                request.setAttribute(CONTEXT_KEY, oldContext);
            }
        }
         
        protected void dispatch(HttpServletRequest request, HttpServletResponse response, String path)
                throws ServletException, IOException {
            //這里調用加載文件會出現404錯誤 /WEB-INF/decorators/decorator.ftl
            RequestDispatcher dispatcher = servletContext.getRequestDispatcher(path);
            if (dispatcher == null) {
                throw new ServletException("Not found: " + path);
            }
            dispatcher.forward(request, response);
        }



       

      posted @ 2016-02-02 11:00  懶惰的肥兔  閱讀(6611)  評論(1)    收藏  舉報
      主站蜘蛛池模板: 国产精品第一二三区久久| 成人午夜在线观看日韩| 久久中文字幕无码一区二区| 99RE8这里有精品热视频 | 99久久国产成人免费网站| 在线观看中文字幕国产码| 国产稚嫩高中生呻吟激情在线视频| 亚洲区日韩精品中文字幕| 国产品精品久久久久中文| 成人精品一区日本无码网| 国产高清在线a视频大全| 日韩中文字幕一区二区不卡 | 成人午夜无人区一区二区| 精品少妇爆乳无码aⅴ区| 成人无码区在线观看| 野花社区在线观看视频| 蜜臀av无码一区二区三区| 亚洲欧美偷国产日韩| 青青草原国产AV福利网站| 一区天堂中文最新版在线| 欧美人与动牲交A免费观看| 国产成人无码区免费内射一片色欲 | 成人免费A级毛片无码片2022 | 亚洲成人免费一级av| 日韩人妻一区中文字幕| 亚洲欧美人成电影在线观看 | gogogo在线播放中国| 国产伦一区二区三区视频| 亚洲中文无码av永久不收费| 天天噜噜日日久久综合网| 亚洲真人无码永久在线| 国产精品小一区二区三区| 亚洲国产日韩欧美一区二区三区| 国产高清午夜人成在线观看,| 青青草国产精品一区二区| 亚洲国产欧美在线看片一国产| 午夜福利偷拍国语对白| 国产亚洲精品久久久久久大师| 天天看片视频免费观看| 国产在线视频一区二区三区| 国产一区二区三区乱码在线观看|