OpenCMS创建导航条

OpenCMS首页导航条代码,在VFS中的/system/modules/org.opencms.welcome/elements/welcome_nav.jsp

 1 <%@ page import="org.opencms.jsp.*" %><%   
2
3 /*
4 * This is a simple example on how to build a dynamic navigation using JSP in OpenCms.
5 * It serves the purpose of demonstrating
6 * the general way to build a dynamic navigation using OpenCms resource properties.
7 */
8
9 // Create a JSP action element
10 CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
11
12 // Some shortcuts to often used Strings
13 String filename = cms.getRequestContext().getUri(); /*filename为页面名,比如url为http://localhost:8080/opencms/opencms/index.jsp,filename为/index.jsp*/
14 // List of all pages / subfolders (sorted by NavPos property)
15 java.util.List list = cms.getNavigation().getNavigationForFolder(); //得到同层目录的所有文件的list
16 java.util.Iterator i = list.iterator();
17
18 // Now build the navigation
19 out.println("<p class=\"small\">Navigation: ");
20
21 while (i.hasNext()) {
22 CmsJspNavElement ne = (CmsJspNavElement)i.next();
23 if (! ne.getResourceName().equals(filename)) {
24 out.println("<a href=\"" +
25 cms.link(ne.getResourceName()) + "\">"
26 + ne.getNavText() + "</a>"); //ne.getNavText()为的navigationtext属性
27 } else {
28 out.println(ne.getNavText()); //页面本身
29 }
30 if (i.hasNext()) {
31 out.println(" | ");
32 }
33 }
34 out.println("</p>");
35 %>



原文地址:https://www.cnblogs.com/zengyou/p/2185316.html