Struts, Ajax, Restful, and Web Service (1)

Source: Internet
Author: User
Tags file url

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.

Related Article

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.