Take a brief introduction to the previous article. The following describes the general structure of the entire framework in detail.
First, let's take a look at the structure of the entire framework package:
It can be seen that the Framework contains very few packages, and the package structure is also super simple. The relationship between filters, ActionSupport, and Router is described as follows:
The diagram is not standardized, so we cannot tell which UML diagram is used. However, we can also see the basic process of the framework when a request arrives. First, the Filter intercepts all requests, and then sends the requests to all registered Router classes. If the requested Url is exactly what a Router wants to intercept, the request is sent to the Router, the framework no longer transmits requests downward. After obtaining the request, the Router analyzes the Url and sends the request to the subclass of the corresponding ActionSupport through the Url Information.
Filters are used for interception. Like most web frameworks, filters are more capable of distributing requests than servlets. First, configure the UrlFilter class of the Framework in the web. xml file of a web project to intercept all requests. Note that the dispatcher should be set to request. If forward is set, the internal forward of the framework will be blocked by the framework, resulting in an infinite loop. Url-pattern is set to/*, indicating that all requests will be intercepted, so that the url distribution right is handed over to the framework itself, rather than using the url distribution policy in jsp specifications. When the Framework processes the URLs of all requests, it is handed over to each Router class for processing in sequence. If the Router Class determines that it complies with its own url format, it is distributed to action for processing. If it cannot be processed and then handed over to the next level of the Router, the last url is processed by all the Router, the rest of the resource File url, such as the http://xxx.xxx.xxx.jpg, then the Framework calls the doChain () method of the filter, use filter to access resources in the web.
<Filter> <Filter-name> unicornWeb </filter-name> <Filter-class> com. mh. mvc. filter. UrlFilter </filter-class> </Filter> <Filter-mapping> <Filter-name> unicornWeb </filter-name> <Url-pattern>/* </url-pattern> <Dispatcher> REQUEST </dispatcher> </Filter-mapping> |
This is the general principle. Next I will introduce the detailed implementation of the Framework.