最近因为工作的原因,使用到了StrutsMenu,对它做了一些初步的了解,想跟大家分享一下.Struts Menu应用是一个JSP标记的集合,支持从XML文件生成各种不同菜单系统,Struts Menu的相关资料中,有一个事例,集中演示了各种不同形态的菜单,包括静态的和动态的,也包含基于用户权限的菜单,还是对我们使用Struts Menu很有帮助的。我也做了一个关于Struts Menu的小例子,感觉需要的包还真不少,我在附件中提供给大家.下面是一个非常简单的,显示Struts Menu中一种菜单--CoolMenu菜单,供大家参考. (参考了其他相关资料)
1、将需要的类库包拷贝到 WEB-INF/lib/目录下 ,如struts-menu.jar、jstl-1.0.6.jar、standard-1.0.6.jar 、commons-collections-3.0.jar、velocity-tools-view-1.0.jar、velocity-1.4.jar、log4j-1.2.8.jar、commons-lang-2.1.jar等,所有的类库包在附件的事例中提供;
2、将 /lib/struts-menu.tld、struts-menu-el.tld拷贝到WEB-INF/lib/目录下;
3、将struts-menu.war中的scripts、styles、images目录拷贝到你的应用"/"目录下;WEB-INF目录下的classes目录拷贝到工程WEB-INF下;META-INF目录下的INDEX.LIST拷贝到工程的META-INF目录下。
4、修改 web.xml 加入 context-param及 taglib 的调用。
- <context-param>
- <param-name>javax.servlet.jsp.jstl.fmt.localizationContextparam-name>
- <param-value>TrackerResparam-value>
- context-param>
- <taglib>
- <taglib-uri>/tags/struts-menutaglib-uri>
- <taglib-location>/WEB-INF/tld/struts-menu.tldtaglib-location>
- taglib><taglib>
- <taglib-uri>/tags/struts-menu-eltaglib-uri>
- <taglib-location>/WEB-INF/tld/struts-menu-el.tldtaglib-location>
- taglib>
<o:p> 5、修改 struts-config.xml 加入 plugin描述及message-resources. 6、配置menu-config.xml,代码在事例中. <o:p></o:p></o:p>
- <plug-in className="net.sf.navigator.menu.MenuPlugIn">
- <set-property property="menuConfig" value="/WEB-INF/menu-config.xml"/>
- plug-in>
- <message-resources parameter="TrackerRes"/>
- <message-resources parameter="ISOCodeRes" key="ISOCodeRes"/>
6、配置menu-config.xml,描述Strut-menu将采用的显示方式,在jsp文件中选择Displayer;进行相关菜单项目的配置后,就可以在jsp文件中选择显示的菜单。
- <MenuConfig>
- <Displayers>
- <Displayer name="DropDown"
- type="net.sf.navigator.displayer.DropDownMenuDisplayer"/>
- <Displayer name="Simple"
- type="net.sf.navigator.displayer.SimpleMenuDisplayer"/>
- <Displayer name="CoolMenu"
- type="net.sf.navigator.displayer.CoolMenuDisplayer"/>
- <Displayer name="CoolMenu4"
- type="net.sf.navigator.displayer.CoolMenuDisplayer4"/>
- <Displayer name="MenuForm"
- type="net.sf.navigator.example.PermissionsFormMenuDisplayer"/>
- <Displayer name="ListMenu"
- type="net.sf.navigator.displayer.ListMenuDisplayer"/>
- <Displayer name="TabbedMenu"
- type="net.sf.navigator.displayer.TabbedMenuDisplayer"/>
- <Displayer name="Velocity"
- type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
- <Displayer name="XtreeMenu"
- type="net.sf.navigator.displayer.XtreeMenuDisplayer"/>
- <Displayer name="CSSListMenu"
- type="net.sf.navigator.displayer.CSSListMenuDisplayer"/>
- Displayers>
- <Menus>
- <Menu name="indexMenu" title="Examples">
- <Item name="indexMenu1" title="Basic Example"
- toolTip="Shows usage of the menu displayers using defaults."
- page="/menutest1.jsp"/>
- <Item name="indexMenu2" title="Advanced Example"
- toolTip="Shows customized menu displays."
- page="/menutest2.jsp"/>
- <Item name="indexMenu3" title="CoolMenu Example"
- toolTip="Shows menu using CoolMenu3"
- page="/coolmenu1.jsp"/>
- <Item name="indexMenu4" title="CoolMenu Example - With Form"
- toolTip="Shows menu using CoolMenu3 with forms."
- page="/coolmenu2.jsp"/>
- <Item name="indexMenu5" title="Permissions Example"
- toolTip="Example use of menu disable and permission checking with CoolMenus."
- page="/permissionsForm.jsp"/>
- <Item name="indexMenu6" title="CoolMenu4 Example"
- toolTip="Shows menu using CoolMenu4"
- page="/coolmenu4.jsp"/>
- <Item name="indexMenu7" title="Expandable DHTML List Example"
- toolTip="Shows Expandable DHTML list"
- page="/dhtmlExpandable.jsp"/>
- <Item name="indexMenu7" title="Dropdown DHTML List Example"
- toolTip="Shows Dropdown DHTML list"
- page="/dhtmlDropdown.jsp"/>
- <Item name="indexMenu8" title="Roles Menu Example"
- toolTip="Shows Menus based on user's role"
- page="/rolesMenu.jsp"/>
- <Item name="indexMenu9" title="Tabbed Menu Example"
- toolTip="Shows Tabbed-based Menu"
- forward="tabbedMenu"/>
- <Item title="Velocity Template Menu"
- toolTip="Shows very simple Velocity generated Menu"
- page="/velocity.jsp"/>
- <Item title="Velocity CoolMenus Menu"
- toolTip="Shows Velocity generated CoolMenu"
- page="/velocity-coolmenu4.jsp"/>
- <Item title="Velocity XTree Menu"
- toolTip="Shows Velocity generated XTree"
- page="/velocity-xtree.jsp"/>
- <Item title="Velocity Tabbed Menu"
- toolTip="Shows Velocity generated Tabbed Menu"
- page="/velocity-tabs.jsp?Home"/>
- <Item title="Nice Looking Tabbed Menu"
- toolTip="Shows Velocity generated Tabbed Menu"
- page="/velocity-nicetabs.jsp?Home"/>
- <Item title="EL (Expression Language) enabled Menu"
- toolTip="Shows very simple Velocity EL Menu"
- page="/velocity-el.jsp"/>
- <Item title="Dynamic, Databased-driven Menu"
- toolTip="Shows very simple menu built from a database table"
- page="/dynamicMenu.jsp"/>
- <Item title="CSS-based Drop-down Menu: Horizontal [New!]"
- toolTip="CSS-only Horizontal drop-down menu"
- page="/cssHorizontal.jsp"/>
- <Item title="CSS-based Drop-down: Vertical [New!]"
- toolTip="CSS-only Vertical drop-down menu"
- page="/cssVertical.jsp"/>
- Menu>
- <Menu name="projectMenu" title="Project Menu">
- <Item title="Home" toolTip="Return to List of Menus" page="/index.jsp"/>
- <Item title="Documentation" toolTip="View Project Documentation"
- location="http://struts-menu.sf.net"/>
- <Item title="FAQs" toolTip="View Frequenty Asked Questions"
- location="http://struts-menu.sf.net/faq.html"/>
- <Item title="Mailing Lists" toolTip="Subscribe to Mailing Lists"
- location="http://sourceforge.net/mail/?group_id=48726"/>
- <Item title="Mailing List Archives"
- toolTip="Search the Mailing List Archives"
- location="http://www.mail-archive.com/index.php?hunt=struts-menu"/>
- Menu>
- <Menu name="ToDoListMenuFile" title="FILE" description="test" width="50">
- <Item name="TDLnew" title="NEW">
- <Item name="TDLnewcase" title="CASE" image="images/case-new.png"
- location="NewCase.jsp"/>
- <Item name="TDLnewitem" title="ITEM" image="images/item-new.png"
- location="index.jsp"/>
- <Item name="TDLnewparty" title="PARTY" image="images/party-new.png"
- location="index.jsp"/>
- Item>
- <Item name="TDLopen" title="OPEN">
- <Item name="TDLopencase" title="CASE" image="images/case-open.png"
- location="index.jsp"/>
- <Item name="TDLopenitem" title="ITEM" image="images/item-open.png"
- location="index.jsp"/>
- <Item name="TDLopenparty" title="PARTY" image="images/party-open.png"
- location="index.jsp"/>
- Item>
- <Item name="TDLexit" title="EXIT"
- image="images/exit.png" location="index.jsp"/>
- Menu>
- MenuConfig>
7、在jsp文件(如Struts-tiles中使用了menu.jsp)中加入,可以通过对useMenuDisplayer来设置菜单的显示风格。
<o:p>- <%@ page contentType="text/html; charset=UTF-8" %>
- <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
- <%@ taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
- <%@ taglib uri="http://struts-menu.sf.net/tag-el" prefix="menu-el" %>
- <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
- <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
- <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
- <html>
- <head>
- <title>Struts Menu Examplestitle>
- <link rel="stylesheet" type="text/css" media="screen"
- href="styles/global.css" />
- head>
- <body>
- <div id="content">
- <script type="text/javascript" src="./scripts/coolmenus3.js">script>
- <script type="text/javascript" src="./scripts/coolmenu-config.js">script>
- <menu:useMenuDisplayer name="CoolMenu" bundle="org.apache.struts.action.MESSAGE">
- <menu:displayMenu name="ToDoListMenuFile"/>
- <menu:displayMenu name="ToDoListMenuEdit"/>
- <menu:displayMenu name="CaseDetailMenuCase"/>
- <menu:useMenuDisplayer>
- >
- > 8、可以在浏览器中显示了。
- >
</o:p>