Tomcat Admin Tree -jakarta Struts Series

zhaozj2021-02-16  52

Tomcat is the JSP / Servlet Reference Implementation provided by Jakarta, the main developer Craig McClanahan is also the main developer of Struts, so he uses Struts to establish Tomcat Admin, as an environment that manages Tomcat Server, when you install Tomcat When you only need http: // localhost: 8080 / admin, you can connect to the Administrator's page. It uses the Memory Realm authentication mode, and a login page will be logged in,

Users who can log in will be based on your% catalina_home% / conf /.

XML Version = '1.0' encoding = 'UTF-8'?>

In this example, only admin Role is only admin, his password is blank, so we can use, username = "admin", password = "", to log in to this system. So, why use admin role , Not 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 APPLICATION

admin

Whether Authetication or Authorization is only the setting-related admin role, you must modify this file when you want new or modify the relevant AA, you must comply with your environment.

After the landing is complete, there will be an administrator interface, as for his role is to manage the entire Tomcat related setup file,

And this time we have to explore how to use the entire Tomcat Admin's operation, but the left control tree menu.

Introduction to Section 02 TreeControlNode

Every tree node is a TreeControlNode, mainly setting

Name: This node name icon: Picture of this node Label: Description of this node Action: Whether to have a link target: Frame (frame) expanded: Whether to expand Treebuilder, it is a collection of treecontrolNode, we can view the generation Root method. TreeControlNode root = new treecontrolNode ("root-node", null, rootnodename, "setuptree.do?select=root-node", "content", true, domain); it is not difficult to find, that is, this is produced Tree node.

Introduction to Section 03 TreeControl

Org.apache.Webapp.admin.SetuPtreeAction is an important action for the entire Tree initialization. For the first time, all web information will be generated here to create all the data into the session, you will see servlet.getServletConfig (). GetInitParameter ("...") will be used to use the init-parameter setting value in web.xml, the next operation is more important, the involvement is relatively wide, we will put root in TreeControl, TreeControl Control = New TreeControl (root); first build a root TREENODE, we will set TreeControl according to this root, which is the root of the entire tree structure. Please note that we will put it in the session is TreeControl but this time, TreeControl only root This root node. Next, we will put the entire tree structure in TreeControl, what should I do, how to deal?

We use Treebuilder (Builder Pattern) you will see some complex code, it doesn't matter, he will build a lot of Tree's Treebuilders in Web.xml to see-PARAM to see -org.apache.Webapp.Admin.tomcattreebuilder, - Org.apache.webapp.admin.resources.resourceStreebuilder, -org.apache.webapp.admin.users.USerstreebuilder These Treebuilders, but I only explain that UserStreeBuilder is enough to let everyone know. Basically, we will be org.apache. Webapp.admin.users.userstreebuilder newinstance () generates an object, then use buildtree () to produce the entire tree structure in TreeControl ~

Section 04 Treebuilder Introduction

TreeBuilder is an interface, the front end of our procedure is invoked to generate TreeBuilder Tree placed in Session, public interface TreeBuilder {public void buildTree (TreeControl treeControl, ApplicationServlet servlet, HttpServletRequest request);} org.apache.webapp.admin.users e.g. In .USERSTREEBUILDER, we can see that he implements buildtree (), the most important thing is to generate all child nodes, then starting all the nodes all of the ADD from root, at this time, all tree materials are put treeControl in this 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);} It is obvious, we can know that this UserStreeBuilder is generated by Tomcat Admin's User Definition. There is a child node of Users, Groups, and Roles, when you choose any child node, he There will be an action of an action to Server, and modify the related tree settings to generate a tree module that should be displayed, and the management screen. Excribed 05 TreeControlTag

In Org.apache.Webapp.admin.treeControlTag, the most important thing is to get TreeControl from Session and generate related HTML code according to the content inside. // Treecontrol protected TreeControl gettreeControl () throws jspexception {...... .. If you are not familiar, you will be a matter of course. This taglib is also the core of the entire tree structure. He will change your tree structure according to your webpage, if necessary, if necessary, for example Checkbox's processing,  You can modify the render section of this program to have a checked feature.

Introduction to Section 06 Tree-Control-Test.jsp

You can see the setuptreeAction, which is Forward to Tree Control Test, Tree Control Test in Struts-Config.xml is pointing to Tree-Control-Test.jsp In this JSP, simple taglib call

You can generate all the tree structure. However, you can see that every node's action is TreeControltest.do. So in the end, check TreeControlTestSt from struts-config.xml means org.apache.Webapp.admin.treeControlTestest This program. Basically you will pass this parameter, if you now make an expand = true modified to false, you can also pass this parameter, which is now this TreeControlNode is selected.

Section 07 Conclusion

转载请注明原文地址:https://www.9cbs.com/read-19954.html

New Post(0)