Struts-menu User Guide

Source: Internet
Author: User
Tags tld
Struts-menu User Guide

I. Introduction
Struts-menu is a menu generation application framework based on Struts framework, it is open source software, can be obtained from the http://www.sourceforge.net. Struts-menu is the easiest way to do without permission control. You only need to configure the file to generate the required menu. To control menu permissions, you can use Tomcat (or other J2EE containers) you can also use the background database to implement permission control.
Obtain the Struts-menu from sourceforge.net and decompress it to obtain some files as shown in 1:

The struts-menu-2.3.jar for its core package, the struts-menu.tld for its corresponding label; The struts-menu.war for Struts-menu comes with the sample; doc directory for help documentation.
Ii. UseStruts-menu(No permission Control)
1. Copy struts-menu.jar to the Web-inflib directory;
2. Copy the struts-menu.tld to the WEB-INF directory;
3. Copy the scripts, styles, and images directories in the struts-menu.war to your application "/" Directory;
4. In addition, Struts-menu requires log4j support, so you need to copy the log4j package to WEB-INF/LIB;
5. Modify the call for Adding web. XML to taglib:
<Taglib>
<Taglib-Uri>/WEB-INF/struts-menu.tld </taglib-Uri>
<Taglib-location>/WEB-INF/struts-menu.tld </taglib-location>
</Taglib>
6. Modify the struts-config.xml and add the following plug-in code in it:
<Plug-in classname = "net. SF. Navigator. Menu. menuplugin">
<Set-Property = "menuconfig" value = "/WEB-INF/menu-config.xml"/>
</Plug-in>
7. Configure menu-config.xml (this file is located under the WEB-INF directory)
<? XML version = "1.0" encoding = "UTF-8"?>
<Menuconfig>
<Displayers>
<Displayer name = "coolmenu" type = "net. SF. Navigator. displayer. coolmenudisplayer"/>
<Displayer name = "listmenu" type = "net. SF. Navigator. displayer. listmenudisplayer"/>
<Displayer name = "dropdown" type = "net. SF. Navigator. displayer. dropdownmenudisplayer"/>
<Displayer name = "simple" type = "net. SF. Navigator. displayer. simplemenudisplayer"/>
<Displayer name = "coolmenu4" type = "net. SF. Navigator. displayer. coolmenudisplayer4"/>
<Displayer name = "menuform" type = "net. SF. Navigator. example. permissionsformmenudisplayer"/>
<Displayer name = "tabbedmenu" type = "net. SF. Navigator. displayer. tabbedmenudisplayer"/>
<Displayer name = "velocity" type = "net. SF. Navigator. displayer. velocitymenudisplayer"/>
</Displayers>
<Menus>
<! -- =============================== To do list menus ============================ ============== -->
<Menu name = "todolistmenufile" Title = "operator" Description = "this is a file menu test" width = "50">
<Item name = "tdlnew" Title = "admin">
<Item name = "tdlnewcase" Title = "go to admin page" image = "images/case-new.png" location = "/webmodule/admin. jsp"/>
<Item name = "tdlnewitem" Title = "new item" image = "images/item-new.png" location = "index. jsp"/>
<Item name = "tdlnewparty" Title = "new party" image = "images/party-new.png" location = "index. jsp"/>
<Item name = "tdlopen" Title = "open">
<Item name = "tdlopencase" Title = "open case" image = "images/case-open.png" location = "index. jsp"/>
<Item name = "tdlopenitem" Title = "open item" image = "images/item-open.png" location = "index. jsp"/>
<Item name = "tdlopenparty" Title = "open party" image = "images/party-open.png" location = "index. jsp"/>
</Item>
<Item name = "tdlexit" Title = "exit" image = "images/exit.png" location = "index. jsp"/>
</Menu>
<! -- =============================== To do list menu edit ======================== ================ -->
<Menu name = "todolistmenuedit" Title = "edit">
<Item name = "tdlselect" Title = "select_all" image = "images/select-all.png" location = "index. jsp" width = "100"/>
<Item name = "tdlprefs" Title = "user_preferences" image = "images/prefs.png" location = "index. jsp" width = "150"/>
</Menu>
<! -- =============================== Permissions menu ===================== ============ -->
<Menu name = "Permissions" Title = "Permissions">
<Item Title = "change" location = "permissionsform. jsp? Username = 'test' "/>
</Menu>
</Menus>
</Menuconfig>
Note:
The code between <displayers> and </displayers> defines the menu format.
The code between <menus> and </menus> defines the menu to be displayed.
The code between <menu> and <menu> has various attributes that define a menu, such:
<Menu name = "todolistmenufile" Title = "operator" Description = "this is a file menu test" width = "50">
The name specifies the name used to display the menu on the JSP page. The title attribute defines the display name of the menu, and the description attribute defines the description information displayed when you move the cursor over the menu, the width attribute defines the width of the menu.
The <item/> label under <menu> defines the sub-item of this menu, for example:
<Item Title = "change" location = "permissionsform. jsp? Username = 'test' "/>
Here, title is the name displayed for the subitem, and location is the operation to be performed when you click this item. In this way, when you click the "change" menu, it will go to the permissionsform. jsp page.
8. Add the following code to the JSP page:
<Menu: usemenudisplayer name = "listmenu" bundle = "org. Apache. Struts. Action. Message">
<Menu: displaymenu name = "todolistmenufile"/>
<Menu: displaymenu name = "todolistmenuedit"/>
<Menu: displaymenu name = "Permissions"/>
</Menu: usemenudisplayer>
Note:
The name attribute specifies the appearance style of the menu to be displayed, which is specified by <displayers> </displayers>.
Ø bundle is the name of the displayed menu, which must be org. Apache. Struts. Action. Message.
<Menu: displaymenu/> defines the menu to be displayed. The name here is the name of the menu to be displayed, which is specified by <menu/>.
In addition, the specified CSS and JavaScript code must be referenced for different menu appearances.
Shows the effect:

Iii. Based onTomcatPermission control menu display
To enable container-based security authentication in struts:
1. You need to configure it in Web. XML (see struts related books ):
<Security-constraint>
<Web-resource-collection>
<Web-resource-Name> adminpages </Web-resource-Name>
<Description> administroat only access </description>
<URL-pattern>/security. jsp </url-pattern>
<Http-method> post </HTTP-method>
<Http-method> Get </HTTP-method>
</Web-resource-collection>
<Auth-constraint>
<Role-Name> Tomcat </role-Name>
<Role-Name> role1 </role-Name>
<Role-Name> admin </role-Name>
</Auth-constraint>
</Security-constraint>
<Login-config>
<Auth-method> basic </auth-method>
<Realm-Name> adminrealm </realm-Name>
</Login-config>
<Security-role>
<Description> administrator </description>
<Role-Name> Tomcat </role-Name>
</Security-role>
<Security-role>
<Description> A second role (to prove a comma-delimited list works) </description>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.