struts2集成sitemesh

网上好多都是关于struts2.1.3之前的版本和sitemesh的集成,后来我查了一下官网,看到下面这句话:

With Struts 2 makes sure to place SiteMesh before the FilterDispatcher filter in your web.xml. You will also want to have consideration for using ActionContextCleanUp filter.

Since Struts 2.1.3, use StrutsPrepareAndExecuteFilter and corresponding clean up filters.

上边的大概意思是说struts2使用FilterDispatcher过滤器的时候,我们要想使用sitemesh,必须使用ActionContextCleanUp过滤器。从2.1.3之后我们使用StrutsPrepareAndExecuteFilter过滤器,也要使用相应的清扫过滤器。所以我们把StrutsPrepareAndExecuteFilter分成两个过滤器StrutsPrepareFilter和StrutsExecuteFIlter,这是因为在strtus2的架构中总是以StrutsPrepareFilter开始,后边跟着其他的过滤器,最后才有StrutsExecuteFIlter来处理请求,因此我们的过滤器顺序就应该是:

1、StrutsPrepareFilter

2、SIteMeah

3、StrutsExecuteFIlter

相应代码:

<filter>
        <filter-name>struts2Pre</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
    </filter>
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
    <filter>
        <filter-name>struts2Exe</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2Pre</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>struts2Exe</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
sitemesh的使用在此就不写了,网上的教程一搜一大把

ps:写的不太好,要是各位有什么问题呢,别喷,请留言交流一下

你可能感兴趣的:(struts2,sitemesh)