Volume 1
Technical manual series
WEB application programming using ACTIONHANDLER
Technical manual series
WEB application programming using ACTIONHANDLER
x xie ke
table of Contents
Chapter 1 ActionHandler Introduction 2
Destination 2
ActionHandler's Structure 2
Chapter II 5 ActionHandler
Chapter III ActionHandler API Reference 7
Class ActionHandler 7
Class generalhandlesvt 13
Chapter 4 Configures ActionHandler 16 in Tomcat
Download 16
Installation 16
Example and application 16
Chapter One
Chapter 1 ActionHandler Introduction
Introduction to the purpose, composition and implementation of ActionHandler
purpose
Web applications include clients and server, as follows
Client: Write a Form, including the data to be processed, the action of the Action point to a servlet
Server side: Write a servlet, accept the request for the specified client, take it out of the customer data, make the corresponding processing, go to the next page according to the processing result
The client, that is, the JSP page, mainly for display. The main business logic, as well as process control, all in servlet.
In a web application, the customer's request is very much, each clicking on the user, almost all corresponds to the customer request, we may write a lot of servlets to handle these different requests. But soon, I will find that there are many things that these servlets do, such as: permission control, take client data, page forwarding ..., there are many similar operations, such as paging query, basics Increase and deletion, etc. ..., each time you write, this feeling is very bad, so you should consider Extract out a super class, let this Super Class to do these repetitive work, so we have A SUPER Servlet, all servlets have inherited it, although our servlet has not been reduced, but still needs to modify the web app configuration file for increasing servlets, but work is obviously more easily.
But things have not finished, because the client requests are very much, we can't write a servlet for each request, so a servlet handles multiple requests to be inevitable, we will find that in the Dopost method of servlet, there will be one The huge condition judgment code, we analyze the client request, and call different code to handle it, everyone knows, the lengthy method, there are many IF, or many case-s switch is the talented nightmare Maybe you can say that the dopost method can break up into many small methods, yes, you can do this, but you still need to do many parameters between these small methods, not only Request and Response, You cannot use them as an instance variable to avoid the parameters inter-method passes, because the server will generate a servlet's new thread to process a new request, we all know that the thread is shared instance variable, when your instance variable is When sharing between the request, some mistakes that make people can't touch the mind appear.
The above describes the uncomfortable things of the Web development, but the servlet is actually innocent. It is designed to have its truth, and we have to do it, let it reintegrate, let it better Suitable for our web application development, in fact, there are not many we have to do, let ActionHandler to solve these problems. ActionHandler's structure
The main components of ActionHandler are as follows:
◆ Eat servlet generalhandlesvt.java
This servlet is responsible for handling all requests in the system, so it is taking servlet, making an additional benefit is that our Web Application profile will never need to change, because there will never have new servlets.
The thing that GeneralHandlersvt is very simple: Check the "reqtype" parameter from the client (this "reqtype" is the reserved word in ActionHandler, of course, you can use other instead of it, but must be determined before the system began development. ), The value of ReqType is defined in the client, and the format is "aa.bb.cc.dd" or "bb.cc.dd", where CC indicates the class that will handle this request, DD indicates that the specific CC class Which method is to handle the request, BB represents the package name of the class, AA represents the package name (if any) outside of BB, resolve "ReqType", and distribute the request to the specified method of the specified class.
Similar to the GUI programming, each request is simulated into an event, and ReqType indicates the receiver object CC of this event, and the method DD processing this time.
That is, we don't have to pay attention to the dopost method (even if you don't want to REQUEST and RESPONSE objects)
◆ Action processes the parent class object actionHandler.java
All customers request the parent class that handles the class,
This is an abstract class
Each ActionHandler is part of a module (see permission system)
Because GeneralHandlesvt generates a new ActionHandler object to handle it for each customer request, the instance variable of ActionHandler is safe.
When a new ActionHandler is generated, it calls the RUN method.
The RUN method first takes out the caller _employee from the session, and determines whether this caller has access to this module (see the permission system),
Generate a JDO object (see the JDO manual) for customer calls
Take out the data from the client, assemble it into a BizObject object (see the JDO manual), put it in the parameter table, in order to prepare customer calls
Further processing according to the corresponding method according to the customer's request
The above steps If an error is wrong, the corresponding error handling mechanism will process it, according to the type of Exception (controlled error, controlled prompt, unusual exception), respectively, respectively, respectively, respectively, and the JDO object is back. Roll (if you have started your transaction)
If there is no error, the JDO object is submitted to transaction, turn off the database connection, turn the page control mechanism will go to the corresponding page, and set the corresponding page prompt information.
ActionHandler has a built-in tool method:
Can get the current user
Judging whether the current user has permission to a certain function
Set page size
Setting the sort field
Page Display Query Results for a data object
Show a BizObject data object
Display according to a specific SQL paging list
Get a BizObject from the parameter table
...
There are still many things that will not be one more, please refer to the API
Many of these functions such as paging display query results, you need to use the client display page, the client can easily display the data subclass inherited ActionHandler with JSTL, and simply prepare a specific request processing method. Details Examples
Chapter two
Chapter II ActionHandler
Introduction to the calling method of ActionHandler
The client's Action is unified for GeneralHandlesvt.
There must be legal reqtype
The client's request Form uses a specific writing format table name $ field name so that ActionHandler can read and extract BizObject data to the parameter table.
Below is an example of a client form:
Client JSP call UserActionHandler.Add instance: