天天看点

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制作网站母版页面