如何在sitemesh的decorator.xml中获取排除URL

时间:2016-08-18 12:26:01

标签: java freemarker sitemesh front-controller

我使用sitemesh来装饰我的应用程序。并配置一个decorator.xml,如下所示,使一些url不被sitemesh装饰。

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/decorators">
    <excludes>
        <pattern>/xxx/merchant/getimage</pattern>
    </excludes>
   <decorator name="centralized">
     <pattern>/*</pattern>
   </decorator>
</decorators>

我使用过滤器动态控制sitemesh装饰。我怎么知道decorator.xml中使用API​​的排除模式。

public class NewMenuFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) {
    }

    @Override
    public void doFilter(ServletRequest request, 
                         ServletResponse response, 
                         FilterChain chain) 
            throws IOException, ServletException {
        String contextPath = 
             ((HttpServletRequest) request).getRequestURI();
        // if contextPath is match excludes pattern
        request.setAttribute("Header_HeadType", "XXX");
        //else 
        request.setAttribute("Header_HeadType", "YYY");
        chain.doFilter(request, response);
    }
}

0 个答案:

没有答案