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内容如下
<%
@includefile
=
"
/taglibs.jsp
"
%>

<!
DOCTYPEhtmlPUBLIC
"
-//W3C//DTDXHTML1.0Strict//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
"
>

<
htmlxmlns
=
"
http://www.w3.org/1999/xhtml
"
xml:lang
=
"
en
"
lang
=
"
en
"
>
<
head
>
<
title
>
StrutsMenuExampleApplication
</
title
>

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

<
scripttype
=
"
text/javascript
"
src
=
"
scripts/nicetabs.js
"
></
script
>

<
linkrel
=
"
stylesheet
"
type
=
"
text/css
"
media
=
"
screen
"
href
=
"
styles/global.css
"
/>
<
linkrel
=
"
stylesheet
"
type
=
"
text/css
"
media
=
"
screen
"
href
=
"
styles/nicetabs.css
"
/>

</
head
>
<
bodyid
=
"
index
"
>
<
divid
=
"
content
"
style
=
"
width:100%
"
>
<
h2
>
StrutsMenuExamples
</
h2
>
<
p
>
Clickonthemenulinksbelowtoseethedifferenttypesofmenus
supportedbyStrutsMenu.
</
p
>

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

</
div
>

<
divid
=
"
footer
"
>
<
ahref
=
"
http://struts-menu.sf.net
"
>
StrutsMenuHomepage
</
a
>
</
div
>
</
body
>
</
html
>
WEB-INF下建立struts-config.xml内容如下
<?
xmlversion
=
"
1.0
"
encoding
=
"
ISO-8859-1
"
?>

<!
DOCTYPEstruts
-
configPUBLIC
"
-//ApacheSoftwareFoundation//DTDStrutsConfiguration1.1//EN
"
"
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd
"
>
<
struts
-
config
>
<!--
==========
PlugInsConfiguration
==================================
-->
<
plug
-
inclassName
=
"
net.sf.navigator.menu.MenuPlugIn
"
>
<
set
-
propertyproperty
=
"
menuConfig
"
value
=
"
/WEB-INF/menu-config.xml
"
/>
</
plug
-
in
>
</
struts
-
config
>
建立menu-config.xml内容如下
<?
xmlversion
=
"
1.0
"
encoding
=
"
UTF-8
"
?>

<
MenuConfig
>

<
Displayers
>
<
Displayername
=
"
DropDown
"
type
=
"
net.sf.navigator.displayer.DropDownMenuDisplayer
"
/>
<
Displayername
=
"
Simple
"
type
=
"
net.sf.navigator.displayer.SimpleMenuDisplayer
"
/>
<
Displayername
=
"
CoolMenu
"
type
=
"
net.sf.navigator.displayer.CoolMenuDisplayer
"
/>
<
Displayername
=
"
CoolMenu4
"
type
=
"
net.sf.navigator.displayer.CoolMenuDisplayer4
"
/>
<
Displayername
=
"
MenuForm
"
type
=
"
net.sf.navigator.example.PermissionsFormMenuDisplayer
"
/>
<
Displayername
=
"
ListMenu
"
type
=
"
net.sf.navigator.displayer.ListMenuDisplayer
"
/>
<
Displayername
=
"
TabbedMenu
"
type
=
"
net.sf.navigator.displayer.TabbedMenuDisplayer
"
/>
<
Displayername
=
"
Velocity
"
type
=
"
net.sf.navigator.displayer.VelocityMenuDisplayer
"
/>
<
Displayername
=
"
XtreeMenu
"
type
=
"
net.sf.navigator.displayer.XtreeMenuDisplayer
"
/>
<
Displayername
=
"
CSSListMenu
"
type
=
"
net.sf.navigator.displayer.CSSListMenuDisplayer
"
/>
</
Displayers
>

<
Menus
>

<
Menuname
=
"
indexMenu
"
title
=
"
Examples
"
>
<!--
pageattributeindicatingacontextrelativeresource.
Thecontextpathwillbeprependedtothevalue.
-->
<
Itemtitle
=
"
tablemeun
"
toolTip
=
"
Showstablemenu
"
page
=
"
/tablemenu.jsp
"
/>
<
Itemname
=
"
listmenu
"
title
=
"
CoolMenuExample
"
toolTip
=
"
ShowsmenuusingCoolMenu
"
page
=
"
/listmenu.jsp
"
/>
<
Itemtitle
=
"
VelocityXTreeMenu
"
toolTip
=
"
ShowsVelocitygeneratedXTree
"
page
=
"
/velocity-xtree.jsp
"
/>

</
Menu
>

</
Menus
>

</
MenuConfig
>
部署工程,访问,出现如下效果。
这是最普通的效果。
试着往menu-config.xml中加入item对应的menu也会跟着增加。
下篇文章将继续提供一些更漂亮一些的menu
1,tablemenu
新建一个jsp文件tablemenu.jsp,内容如下:
<%
@includefile
=
"
/taglibs.jsp
"
%>

<!
DOCTYPEhtmlPUBLIC
"
-//W3C//DTDXHTML1.0Strict//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
"
>

<
htmlxmlns
=
"
http://www.w3.org/1999/xhtml
"
xml:lang
=
"
en
"
lang
=
"
en
"
>
<
head
>
<
title
>
StrutsMenuExampleApplication
</
title
>

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

<
scripttype
=
"
text/javascript
"
src
=
"
scripts/nicetabs.js
"
></
script
>

<
linkrel
=
"
stylesheet
"
type
=
"
text/css
"
media
=
"
screen
"
href
=
"
styles/global.css
"
/>
<
linkrel
=
"
stylesheet
"
type
=
"
text/css
"
media
=
"
screen
"
href
=
"
styles/nicetabs.css
"
/>

</
head
>
<
divid
=
"
header
"
>
<
menu:useMenuDisplayername
=
"
Velocity
"
config
=
"
/templates/indextabs.html
"
bundle
=
"
org.apache.struts.action.MESSAGE
"
>
<
ulid
=
"
menuList
"
>
<
menu:displayMenuname
=
"
projectMenu
"
/>
</
ul
>
</
menu:useMenuDisplayer
>
</
div
>
<%
@includefile
=
"
/common/footer.jsp
"
%>
</
html
>
在menu-config.xml的menus之间加入如下内容
<
Menuname
=
"
projectMenu
"
title
=
"
ProjectMenu
"
>
<
Itemtitle
=
"
Home
"
toolTip
=
"
ReturntoListofMenus
"
page
=
"
/index.jsp
"
/>
<
Itemtitle
=
"
Documentation
"
toolTip
=
"
ViewProjectDocumentation
"
location
=
"
http://struts-menu.sf.net
"
/>
<
Itemtitle
=
"
FAQs
"
toolTip
=
"
ViewFrequentyAskedQuestions
"
location
=
"
http://struts-menu.sf.net/faq.html
"
/>
<
Itemtitle
=
"
MailingLists
"
toolTip
=
"
SubscribetoMailingLists
"
location
=
"
http://sourceforge.net/mail/?group_id=48726
"
/>
<
Itemtitle
=
"
MailingListArchives
"
toolTip
=
"
SearchtheMailingListArchives
"
location
=
"
http://www.mail-archive.com/index.php?hunt=struts-menu
"
/>
</
Menu
>
部署运行工程,从主页点击tablemenu进入tablemenu的页面如图:
一、在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内容如下






































































































这是最普通的效果。
试着往menu-config.xml中加入item对应的menu也会跟着增加。
下篇文章将继续提供一些更漂亮一些的menu
struts-menu(tablemenu样式)
上篇文章讲了如何使用struts-menu这篇在上篇的基础上增加如果美化menu作出漂亮的menu来1,tablemenu
新建一个jsp文件tablemenu.jsp,内容如下:





























在menu-config.xml的menus之间加入如下内容












