Tomcat admin tree-Jakarta Struts Series

Source: Internet
Author: User
Tags user definition

Tomcat is the JSP/servlet reference implementation provided by Jakarta. The main developer Craig Mcclanahan is also the main developer of Struts. Therefore, he used struts to establish the Tomcat admin project, as an environment for managing Tomcat server, When you install Tomcat, you only need http: // localhost: 8080/admin to connect to the Administrator page, it adopts the memory realm authentication mode and requires you to log on to a login page,

 

Users that can log on will be defined according to the tomcat-users.xml under your % catalina_home %/CONF/admin all users of this role,

XML version = '1. 0' encoding = 'utf-8'?>
In this example, only the admin user with the admin role identity has a blank password, so we can use username = "admin", password = "", to log on to this system. so why is admin role used instead of other role? You must view your % catalina_home %/Server/webapps/admin/WEB-INF/Web. XML,
  Tomcat server configuration security constraint Protected Area *. Jsp *. Do *. Html Admin Form Tomcat server configuration form-based authentication Area
/Login. jsp /Error. jsp The role that is required to log in to the Administration Application Admin
Whether authentication or authorization, only related admin role is set. To add or modify the relevant AA, you must modify this file, to meet your environment.

After login, an administrator interface will appear. Its role is to manage the tomcat-related configuration files,

This time we will discuss not how to use the entire Tomcat Admin Operation, but the left-side control tree menu.

Section 02 introduction to treecontrolnode

Each tree node is a treecontrolnode.

 

Name: name of the node.
Icon: image of this node
Label: Description of the node
Action: Indicates whether a link exists.
Target: the target position (FRAME) after clicking)
Expanded: whether to expand
Treebuilder is the set that generates the treecontrolnode. We can view the method that generates the root node.
Treecontrolnode root = new treecontrolnode ("Root-node", null, rootnodename, "setuptree. do? Select = root-node "," content ", true, domain );
It is not hard to find that every tree node is generated.

Section 03 introduction to treecontrol

Org. apache. webapp. admin. setuptreeaction is an important action for the entire tree initialization. The first time you obtain all the webpage information, all the data will be generated here and put into the session. You will see the servlet. getservletconfig (). getinitparameter ("... ") the Web will be used. the init-Parameter Setting Value in XML is important and involves a wide range of operations. We will put the root in treecontrol,
Treecontrol control = new treecontrol (Root );
To put it simply, first create a root treenode. We will set the treecontrol based on this root, which is the root of the entire tree structure. please note that at last we put the session into treecontrol, but at this time, treecontrol only has the root node root.

Next, we will place the entire tree structure in treecontrol. What should we do?

We use treebuilder pattern and you will see some complicated code. It doesn't matter. It will build many trees that can be stored on the web. -org. apache. webapp. admin. tomcattreebuilder,-org. apache. webapp. admin. resources. resourcestreebuilder,-org. apache. webapp. admin. users. userstreebuilder treebuilder, but I only show that userstreebuilder is enough for everyone to understand. basically, we set Org. apache. webapp. admin. users. userstreebuilder newinstance () generates the object, and then uses buildtree () The entire tree structure can be generated and placed in treecontrol ~

Section 04 introduction to treebuilder

Treebuilder is an interface. Our front-end program calls treebuilder to generate a tree and put it into the session,
Public interface treebuilder {public void buildtree (treecontrol, applicationservlet, httpservletrequest request );}
For example, org. apache. webapp. admin. users. in userstreebuilder, we can see that he implements buildtree (). The most important thing is that in addsubtree (), all child nodes are generated, and then all nodes are added by root. At this time, all tree data is stored in the treecontrol session.
Protected void addsubtree (treecontrolnode root, messageresources resources) {string databasename = urlencoder. encode ("users: TYPE = userdatabase, database = userdatabase"); treecontrolnode subtree = new treecontrolnode ("global user and group Administration", "folder_16_pad.gif", resources. getmessage ("users. treebuilder. subtreenode "), null," content ", true); treecontrolnode groups = new treecontrolnode ("Global administer groups", "groups.gif", resources. getmessage ("users. treebuilder. groupsnode"), "users/listgroups. do? Databasename = "+ urlencoder. encode (databasename) + "& forward =" + urlencoder. encode ("groups list setup"), "content", false); treecontrolnode roles = new treecontrolnode ("Global administer roles", "roles.gif", resources. getmessage ("users. treebuilder. rolesnode ")," users/listroles. do? Databasename = "+ urlencoder. encode (databasename) + "& forward =" + urlencoder. encode ("roles list setup"), "content", false); treecontrolnode users = new treecontrolnode ("Global administer users", "users.gif", resources. getmessage ("users. treebuilder. usersnode ")," users/listusers. do? Databasename = "+ urlencoder. encode (databasename) + "& forward =" + urlencoder. encode ("users list setup"), "content", false); root. addchild (subtree); subtree. addchild (users); subtree. addchild (groups); subtree. addchild (roles );}
Obviously, we can know that this userstreebuilder generates the user definition of Tomcat admin. the following sub-nodes have users, groups, and roles. When you select any sub-node, it will send an action to the server, modify the relevant tree settings to generate the tree module that should be displayed and manage the screen.

Section 05 introduction to treecontroltag

Among the org. Apache. webapp. admin. treecontroltag, the most important thing is to obtain the treecontrol from the session and generate relevant HTML code based on the content in it.
// Obtain treecontrol protected treecontrol gettreecontrol () throws jspexception {........} // generate HTML code protected void render (jspwriter out, treecontrolnode node, int level, int width, Boolean last) throws ioexception {.......}
If you are familiar with tablib, you can take a look at this program. If you are not familiar with it, you will take it for granted. this taglib also controls the entire tree structure. It will change the display mode of your tree structure based on your webpage operations. If necessary, such as adding checkbox processing, you can modify the render part of the program so that it can be checked.

Section 06 introduction to tree-control-test.jsp

You can see that setuptreeaction is finally forward to tree control test, In the struts-config.xml settings tree control test is to refer to the tree-control-test.jsp in this JSP, simple taglib call

All tree structures can be generated. however, you can see that the action of each node is treecontroltest. do. so finally, checking from the struts-config.xml that treecontroltest is Org. apache. webapp. admin. treecontroltest. basically, you will pass in the tree parameter. If you change expand = true to false now, you can also pass in the select parameter, which indicates that the treecontrolnode is selected now.

Section 07 conclusion

The netui: tree component in BEA Workshop 8.1 also uses the same solution to generate a tree. this is a method for generating a dynamic tree menu. compared with a javascript tree downloaded to the client, every time the node is opened and closed, it must communicate with the server, which is resource-consuming. when the browser version of the client is uncertain, using DHTML (HTML + JavaScript) may sometimes cause errors, and sometimes the memory of the client may be insufficient due to the large amount of JavaScript data. In addition, jdon's wys1978 provides a javascript tree for the http://webfx.eae.net/dhtml/xloadtree/xloadtree.html, although it belongs to Javascript, but the difference is that every action is to call the server to obtain data, so, when you use a relatively small system, you can use Struts-menu to download the tree menu at a time. When the data volume is too large or changes frequently, I do not recommend that you download all the data to the client at a time. Therefore, whether it is the taglib solution or xloadtree, it is a good choice.

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.