WEB application programming using ACTIONHANDLER

xiaoxiao2021-03-06  73

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:

The above client Form event receives the object is the useerActionHandler object, the processing method is the add method, the following is the corresponding server-side code:

Server-side UserActionHandler sample code

Public void add () throws sqlexception {

THIS.VALIDCANDO ("user.add") // Is User.Add permissions

THIS._JDO.BEGINTRANS (); // Start transaction processing

BizObject obj = this.getbizObjectFromMap ("user"); // Remove User

THIS._JDO.ADD (OBJ);

this._tipinfo = "Successful operation!" // Client display information

THIS._NEXTURL = "/ user / userinfo.jsp"; // Forward page

}

Below is the query example of the useerActionHandler, Listobj is an ActionHandler built-in query method, which will put the User object ArrayList in the appointed Request's Objlist property, similar methods are Showobj:

UserActionHandler query example

Public void listuser () throws sqlexception {

THIS.VALIDCANDO ("user.list") // Is User.List permissions

this.listobj ("user"); // Start inquiry

THIS._TIPINFO = "Query result!" // Client display information

THIS._NEXTURL = "/ user / userlist.jsp"; // Forward page

}

The client receives the query results example, and take a list from the Request object Objlist property:

Client JSP Receive UseerActionHandler.Listuser Query Results Example:

<% @ taglib prefix = "c" URI = "http://java.sun.com/jsp/jstl/core"%>

$ {Obj.uid}

$ {Obj.name}

third chapter

Chapter III ActionHandler API Reference

ActionHandler API

Class ActionHandler

Java.lang.object

|

- Sand.Depot.ActionHandler.system.ActionHandler

Public Abstract Class ActionHandler

Extends java.lang.Object

AUTHOR:

Administrator to change Type Comment Go to Window> Preferences> Java> Code Generation> Code and Comments

Constructor Summary

ActionHandler (Javax.Servlet.http.httpservletRequest Req, Javax.Servlet.http.httpservletResponse Res) constructor

Method Summary

Void

AddorUpdate () handles added or modified, determined by the value of Objid

Void

AddorUpdate (Tool.dao.abstractsysobj ASO) Processing Add or modify, determine by the value of AbstractSysobj.GetID

Void

Deleteall (java.lang.string objtype)

Void

DESTROY () Clean Up Resources

Void

Dispatch (java.lang.string URL)

Tool.dao.bizObject

GetBizObjectFrommap (java.lang.string bizname) taken from Request to get a good BizObject

Java.util.ArrayList

GetBizObjectWithType (java.lang.string biztype) Repacking BizObject from Request according to BizObject type

Java.lang.string

GETHARDCOREFILTER ()

Java.lang.string

GetORDERBY ()

int

GetPageSize () property _PageSize acquisition method.

Void

ListobjwithQueryFactory (Tool.dao.QueryFactory QueryFactory) Supports multi-BizObject combination query according to custom queryfactory queries

Void

ListobjwithQueryFactory (Tool.da.QueryFactory QueryFactory, java.lang.string QRYPARAM) supports multiple BizObject combination queries according to custom QueryFactory queries

Void

PutbizObjectInmap (Tool.dao.abstractsysobj ASO) placed in BizObject to the map of BizObject installed

Void

RemovebizObjectFrommap (java.lang.string bizname) shifts from Map to assemble BizObjectvoid

Run (java.lang.string methodname) Processing POST Requests Each request request runs this method. The work made by this method: Permissions judgment, whether the current user has basic access to this module to generate the corresponding object type JDO object according to the transmission Into the MehodName call the corresponding method

Void

SetAttribute (java.lang.string attr, java.lang.object value)

Void

Sethardcorefilter (java.lang.string filter)

Void

Setorderby (java.lang.string by)

Void

SetPageSize (int _pageSize) attribute _PageSize setting method.

Methods inherited from class java.lang.object

Equals, Getclass, Hashcode, Notify, NotifyAll, Tostring, Wait, Wait, Wait

Constructor Detail

ActionHandler

Public anctionHandler (javax.servlet.http.httpservletRequest Req,

Javax.Servlet.http.httpservletResponse res)

Constructor

Method detail

GetBizObjectFromMap

Public Tool.dao.bizObject getBizObjectFromMap (java.lang.string bizname)

Take a set of BizObject from the request

Parameters:

Bizname -

Returns:

GetBizObjectwithType

Public Java.util.ArrayList getBizObjectwithType (java.lang.string biztype)

Take a set of BizObject from the request based on the BizObject type

Returns:

RemovebizObjectFrommap

Public Void RemovebizObjectFrommap (java.lang.string bizname)

Remove BizObject from Map

Parameters:

Bizname -

Returns:

PutbizObjectInmap

Public void PutbizObjectInmap (Tool.dao.abstractsysobj ASO)

Add BizObject to the MAP of BizObject to the storage group.

Returns:

ListobjwithQueryFactory

Public void ListobjwithQueryFactory (Tool.dao.QueryFactory QueryFactory,

Java.lang.string qryparam)

Throws Javax.Servlet.ServletException,

Java.sql.sqlexception

Support multiple BIZOBJECT combination queries according to custom queryfactory query

Parameters:

QueryFactory - Custom QueryFactory

QRYPARAM - The specified query object type, if it is empty, all BizObject that came into the query object

Throws:

Javax.Servlet.ServletException

Java.sql.sqlexception

ListobjwithQueryFactoryPublic void ListobjwithQueryFactory (Tool.dao.QueryFactory QueryFactory)

Throws Javax.Servlet.ServletException,

Java.sql.sqlexception

Support multiple BIZOBJECT combination queries according to custom queryfactory query

Throws:

Javax.Servlet.ServletException

Java.sql.sqlexception

Addorupdate

Public void addorupdate (Tool.dao.abstractsysObj ASO)

Throws Javax.Servlet.ServletException,

Java.sql.sqlexception

Processing added or modified, determined by the value of AbstractSysobj.GetID

Parameters:

ASO -

Javax.Servlet.ServletException

Java.sql.sqlexception

Addorupdate

Public void addorupdate ()

Throws Javax.Servlet.ServletException,

Java.sql.sqlexception

Processing added or modified, determined by the value of Objid

Javax.Servlet.ServletException

Java.sql.sqlexception

SetaTribute

Public void setttribute (java.lang.string Attr,

Java.lang.Object value)

Deleteall

Public void deleteall (java.lang.string objtype)

Throws Javax.Servlet.ServletException,

Java.sql.sqlexception

Javax.Servlet.ServletException

Java.sql.sqlexception

DESTROY

Public void destroy ()

Clean Up Resources

Run

Public void run (java.lang.string methodname)

Throws Javax.Servlet.ServletException,

Java.io.ioException

Processing POST Request Each request request will run this method, the work made by this method: Permissions judgment, whether the current user has basic access to this module to generate the corresponding object type JDO object to call the corresponding method according to the incoming mehodname

Parameters:

MethodName - Types To process

Throws:

Javax.Servlet.ServletException

Java.io.ioException

Dispatch

Public void dispatch (java.lang.string url)

Throws Javax.Servlet.ServletException,

Java.io.ioException

Javax.Servlet.ServletException

Java.io.ioException

GETHARDCOREFILTER

Public java.lang.string gethardcorefilter ()

Returns:

Returns the_hardcorefilter.

Sethardcorefilter

Public void sethardcorefilter (java.lang.string filter)

Parameters:

Filter - the_hardcorefilter to set.getorderby

Public java.lang.string getorderby ()

Returns:

Returns the_Orderby.

Setorderby

Public void setORDERBY (Java.lang.String By)

Parameters:

By - the _orderby to set.

GetPageSize

Public int getpagesize ()

Property_PageSize acquisition method.

Returns:

The value of the attribute _Pagesize.

SetPageSize

Public void setpagesize (int _pageSize)

Attribute _PageSize setting method.

Parameters:

_PageSize - the new value of the property _PageSize.

Class generalhandlesvt

Java.lang.object

|

- javax.servlet.GenericServlet

|

- javax.servlet.http.httpservlet

|

- Sand.Depot.Servlet.system.GeneralHandlesvt

All Implement Interfaces:

Java.io.serializable, Javax.Servlet.Servlet, Javax.Servlet.ServletConfig

Public class generalhandlesvt

Extends javax.servlet.http.httpservlet

Eat servlet, process all requests

AUTHOR:

Administrator to change Type Comment Go to Window> Preferences> Java> Code Generation> Code and Comments

See Also:

Serialized Form

Constructor Summary

GeneralHandlesvt ()

Method Summary

Void

DESTROY () Clean Up Resources

Void

Doget (javax.servlet.http.httpservletRequest Req, javax.servlet.http.httpservletResponse res) process the http get request

Void

Dopost (javax.servlet.http.httpservletRequest Req, javax.servlet.http.httpservletResponse res) Handle POST request

Methods inherited from class javax.servlet.http.httpservlet

Service

Methods inherited from class javax.servlet.GenericServlet

GetInitParameter, GetInitParameterNames, GetServletConfig, GetServletContext, GetServletInfo, GetServletName, Init, Init, Log, LOG

Methods inherited from class java.lang.object

Equals, Getclass, Hashcode, Notify, NotifyAll, Tostring, Wait, Wait, Wait

Constructor Detail

GeneralHandlesvtpublic generalhandlesvt ()

Method detail

DESTROY

Public void destroy ()

Clean Up Resources

Specified by:

Destroy in interface javax.servlet.servlet

OVERRIDES:

Destroy in class javax.servlet.genericServlet

doget

Public void doget (javax.servlet.http.httpservletRequest Req,

Javax.Servlet.http.httpservletResponse res)

Throws Javax.Servlet.ServletException,

Java.io.ioException

Process the HTTP Get Request

OVERRIDES:

Doget in class javax.servlet.http.httpservlet

Parameters:

REQ - HTTP request

Res - http response

Throws:

Javax.Servlet.ServletException

Java.io.ioException

Dopost

Public void dopost (javax.servlet.http.httpservletRequest Req,

Javax.Servlet.http.httpservletResponse res)

Throws Javax.Servlet.ServletException,

Java.io.ioException

Handling POST request

OVERRIDES:

Dopost in class javax.servlet.http.httpservlet

Throws:

Javax.Servlet.ServletException

Java.io.ioException

Chapter Four

Chapter 4 Configuring ActionHandler in Tomcat

This chapter describes how to configure the Jakarta implementation version of ActionHandler in Tomcat

download

installation

Example and application

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

New Post(0)