jsp:param和meta來控制導航選中與否,頁面組裝器sitemesh

A.jsp

B.jsp

C.jsp

decorators.xml

其中A.jsp是某項功能具體的jsp,A包含B,C是默認模板包含B

注:需要了解sitemesh和decorators頁面組裝器的主要知識http://www.cnblogs.com/luotaoyeah/p/3776879.html

需要下載sitemesh的jar包,不用組裝器也可以實現

http://blog.csdn.net/liu251/article/details/2797488


decorators.xml中主要內容:裝飾器配置文件

    <!-- 默認模板 -->
    <decorator name="default" page="C.jsp">
        <pattern>/*</pattern>
    </decorator>


C.jsp主要內容:網頁組裝的模板

    <sitemesh:usePage id="thePage" />
    <%--菜單選擇 --%>
    <sitemesh:body/>
    <jsp:include page="/B.jsp">
        <jsp:param name="testmenu" value="${thePage.getProperty(\"meta.test\")}"/>
    </jsp:include>


B.jsp主要內容:菜單在這個jsp中來控制,公共頁面

<c:choose>
            <c:when test="${param.testmenu== '1'}">
             
            </c:when>    

            <c:when test="${param.testmenu== '2'}">
             
            </c:when>   

</c:choose>

A.jsp主要內容:獨立頁面

 <meta name="test" content="1" />


前提,每個類似A的獨立頁面都需要有meta,來規定自己的頁面需要位於在那個導航下。

C拿到A的meta爲test的值,賦給B的jsp:param(name爲testmunu),然後B根據${param.testmenu== '1'}來判斷A頁面是要處於那個導航菜單下,來進行導航菜單的一些顏色等設置


如有不明白,繼續溝通

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章