天天看點

Struts2結合sitemesh3制作網站母版頁面

上一篇文章介紹了sitemesh3的使用,這篇文章來介紹如何結合struts2來配置和使用sitemesh,具體的如何使用sitemesh3我就不講解了,這個你們可以看看我的上一篇部落格。

首先你要添加struts和sitemesh相關的jar包:

Struts2結合sitemesh3制作網站母版頁面

添加完畢後,你要配置web.xml檔案:

<?xml version="1.0" encoding="UTF-8"?>

    id="WebApp_ID" version="3.0">

    <!--用來消除sitemesh 攔截器 Struts2攔截器的沖突 使之相容 -->

    <filter>

        <filter-name>struts-cleanup</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>

    </filter>

        <filter-name>sitemesh3</filter-name>

        <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>

        <filter-name>struts2</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    <filter-mapping>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

</web-app> 

配置好了之後要配置struts.xml檔案:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />

    <constant name="struts.devMode" value="true" />

   <package name="aboutme" extends="struts-default">

        <action name="AboutMe"

            class="zw.hellozw.action.AboutMeAction">

            <result>/AboutMe.jsp</result>

        </action>

        <!-- Add actions here -->

    </package>

</struts>

然後你通路看看:

Struts2結合sitemesh3制作網站母版頁面