"Struts" struts initialize the mainline

Source: Internet
Author: User

I. Overview

The portal of the Struts framework is a filter (Strutsprepareandexecuterfilter), which is first introduced when learning Jsp/servlet, which consists of three methods and three parameters in a filter interface-- Init and Dofilter, Destory method, Filterconfig (filter configuration parameter in Web. xml) and protocol-independent ServletRequest, Servletresponse. Throughout the past life of Struts2 appeared, in fact, the whole framework consists of two parts, part of the struts with the HTTP protocol, and the other part of the agreement, and the business logic is closely linked to the xwork part, so the main line can also be carefully divided, Into the HTTP preprocessing (completed by Struts) and the HTTP execution process (completed by Xwork).

View Strutsprepareandexecuterfilter source code, the entire struts framework can be divided into three main lines:

1. Initialize the main line: Init (filterconfig) method-driven;

2. Running Main Line: DoFilter (ServletRequest, Servletresponse) method-driven;

2.1 HTTP preprocessing process: related to struts;

2.2 HTTP execution process: related to xwork;

3. Destruction Main Line: Destory () method-driven;

At this point, all of Struts2 's main lines are listed, this time the main analysis of the struts framework of the initialization of the main line.

Recommended reading: Struts Technology Insider-Lu Zhou "struts in action"


second, the initialization of the main line

The order of initialization of the Web container, Servletcontext>listener>filter>servlet, corresponds to the read order of the configuration in XML. Context-param will be read first, then listener, Filter, the Init-param configured in the servlet tag. So, to use the Struts framework, copy the jar, Configure the Struts.xml file or the most important thing is to configure Strutsprepareandexecuterfilter in Web. XML, otherwise you can't get struts into your project even if you're ready for everything.

Write here to decide not to write, or to see the source code bar, directly see the Init method inside the filter, the main initialization log factory, HTTP preprocessing object prepare, HTTP request processing Object Executer, Most importantly, the entire struts as the Controller--diapatcehr of the MVC framework and its Init method, while the entire Struts core container (struts Ioc/di) is also initialized in dispatcher, in addition, Dispatcher is also responsible for default.properties, Struts-default.xml, Struts.xml, struts-plugin.xml loading, and so on.

It is important to be clear that struts is made up of two parts, in particular, where the dispatcher class, as an adhesive, binds struts and xwork together to form a base point for the STRUTS2 web framework and Web container decoupling. To figure out the STRUTS2 framework, a filter and a dispatcher are the first to understand.


Three, to this end

Struts2 is too "heavy" for the MVC framework of the presentation layer, and now spring MVC is increasingly taking over more markets.

We say layered development is actually a hierarchy for an application: The presentation layer, the business layer, and the persistence layer, struts2 and spring MVC as the MVC framework for the presentation layer. Let's take a look at the frameworks and techniques used in each layer.

Presentation layer: servlet/jsp, Spring MVC, struts2

Business layer: Spring

Persistence layer: JDBC, dbutils, Spring jdbc, Mybatis, hibernate

In addition, if you have the energy to study the java.util.concurrent[.*] package and NIO, these are too many things to do with the principle of machine hardware, it is only necessary for you to step in, such as concurrent programming inside the JMM (Java memory model, not a simple JVM memory classification), It is also necessary to study threadlocal.


Note:

This article lazy not finished, if necessary, please dabigatran discussion (qq:323849607), thank you!

"Struts" struts initialize the mainline

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.