DANCE WITH JAVA

开发出高质量的系统

常用链接

统计

积分与排名

好友之家

最新评论

struts-menu使用教程

struts-menu可以做成各种各样的menu,这里演示一些简单的用法。方便入门
一、在sourceforge上下载最新版本的strutsmenu
http://struts-menu.sourceforge.net/
解压缩zip文件得到struts-menu.war,解压缩它,要用到里边的js文件,imgage文件和css文件等
这个本来是struts-menu的演示工程,本文简化了里边的东西,选择里边比较有代表性的几个拿出。
二、新建一个web工程。
拷贝相应的类库到lib目录下。
velocity-tools-view-1.0.jar
velocity-1.4.jar
struts-menu-2.4.2.jar
struts-1.2.9.jar
standard-1.0.6.jar
log4j-1.2.8.jar
jstl-1.0.6.jar
commons-logging-1.0.4.jar
等,基本就是struts-menu工程中的jar文件
拷贝struts-menu工程中的common     image    scripts    styles   templates等目录到新的web工程 
拷贝taglib.jsp到webroot下
三.新建一个jsp文件index.jsp内容如下
<%@ include file="/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    
<title>Struts Menu Example Application</title>

    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    
<script type="text/javascript" src="scripts/nicetabs.js"></script>
    
    
<link rel="stylesheet" type="text/css" media="screen"
        href
="styles/global.css" />
    
<link rel="stylesheet" type="text/css" media="screen"
      href
="styles/nicetabs.css" />

</head>
<body id="index">
<div id="content" style="width: 100%">
    
<h2>Struts Menu Examples</h2>
    
<p>
        Click on the menu links below to see the different types of menus
        supported by Struts Menu.
    
</p>

    
<menu:useMenuDisplayer name="Velocity" config="/templates/index.html">
        
<ul class="glassList">
        
<menu:displayMenu name="indexMenu"/>
        
</ul>
    
</menu:useMenuDisplayer>

</div>

<div id="footer">
  
<a href="http://struts-menu.sf.net">Struts Menu Homepage</a>
</div>
</body>
</html>
WEB-INF下建立struts-config.xml内容如下
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
  
<!-- ========== Plug Ins Configuration ================================== -->
  
<plug-in className="net.sf.navigator.menu.MenuPlugIn">
    
<set-property property="menuConfig" value="/WEB-INF/menu-config.xml"/>
  
</plug-in>
</struts-config>
建立menu-config.xml内容如下
<?xml version="1.0" encoding="UTF-8" ?>

<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">
        
<!-- page attribute indicating a context relative resource.
             The context path will be prepended to the value. 
-->        
        
<Item  title="tablemeun"
               toolTip
="Shows table menu"
               page
="/tablemenu.jsp"/>
        
<Item  name="listmenu"  title="CoolMenu Example"
               toolTip
="Shows menu using CoolMenu"
               page
="/listmenu.jsp"/>
        
<Item  title="Velocity XTree Menu"
               toolTip
="Shows Velocity generated XTree"
               page
="/velocity-xtree.jsp"/>
               
    
</Menu>

  
</Menus>

</MenuConfig>
部署工程,访问,出现如下效果。


这是最普通的效果。
试着往menu-config.xml中加入item对应的menu也会跟着增加。
下篇文章将继续提供一些更漂亮一些的menu

posted on 2007-05-27 16:59 dreamstone 阅读(6109) 评论(7)  编辑  收藏 所属分类: web框架

评论

# re: struts-menu使用教程 2007-06-05 11:46 @yeafee

继续继续加油加油  回复  更多评论   

# re: struts-menu使用教程 2007-09-13 10:22 我是我

出现错误:
The menu repository could not be found  回复  更多评论   

# re: struts-menu使用教程 2008-08-21 14:10 ttt

@我是我
因为系统没有找到你的menu-config.xml文件,如果你用的是spring框架的话,要在applicationContext.xml中加上下面这句话:
<bean id="menu" class="net.sf.navigator.menu.MenuLoader">
<property name="menuConfig">
<value>/WEB-INF/menu-config.xml</value>
</property>
</bean>
  回复  更多评论   

# re: struts-menu使用教程 2008-09-22 08:09 SS

<bean id="menu" class="net.sf.navigator.menu.MenuLoader">
<property name="menuConfig">
<value>/WEB-INF/menu-config.xml</value>
</property>
</bean>
我添加了这一句话,还是不行,我是用spring security和struts menu结合时候用  回复  更多评论   

# re: struts-menu使用教程 2008-09-23 08:47 SS

希望能得到您的指导  回复  更多评论   

# re: struts-menu使用教程[未登录] 2009-04-07 09:35 kelvin

没有、templates/index.html
  回复  更多评论   

# re: struts-menu使用教程[未登录] 2014-01-01 14:08 程序员

为什么我 用Eclipse 创建了个一样的工程 没有报错,却没任何效果  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: