Struts Journey (i) Struts introduction and principles

Source: Internet
Author: User
Tags config


about Struts

Struts is an open source project sponsored by the Apache Software Foundation (ASF). It was originally a subproject in the Jakarta Project and became the top-level project for ASF in March 2004. Using javaservlet/jsp technology, it realizes the application framework of MVC design pattern based on Javaeeweb application and is a classic product in MVC Classic design pattern. Struts Development History

Struts is part of the Apachejakarta project, and the founders of the project want to improve and improve javaserverpages, Servlets, tag libraries, and object-oriented technical standards through research on the project.

The name struts comes from supporting metal frames used in buildings and old-fashioned aircraft. The reason this framework is called "struts" is to remind us to remember the foundations underpinning our houses, buildings, bridges, and even our stilt feet. This is also an excellent description of the role struts plays in developing Web applications.

Struts means "pillars, branches," which are designed to reduce program development time, and project creators believe that the existence of Jsp,servlet can help users solve most problems, but because of their coding on the development of the project has brought a lot of inconvenience, reusability is also poor, So struts came into being to help users solve these problems in the shortest possible time. The Struts framework provides the following services:

(1) as a servlet for the controller.

(2) Provide a large number of tag libraries.

(3) Provide a framework for internationalization, using different profiles, can help users to choose the appropriate language.

(4) A JDBC implementation is provided to define the data source and database connection pool.

(5) XML parsing tool.

(6) file download mechanism.

Struts Principle

Struts is an implementation of the JSPMODEL2 design Standard, which describes the architecture and working principles of struts from the model, view, and Controller 3 sections, respectively. The invocation process is as follows (Figure 1.1).


Figure 1.1

(1) Views (view)

In struts, the view layer contains two parts, a JSP page, and a actionform.

Actionform encapsulates the user-submitted form information, in fact Actonform is essentially javabean, these javabean do not have business logic, only provide all the properties of getter and setter method, These properties correspond to the entries in the user form that are one by one. In struts, the user form information is submitted to the controller via Actionform.

JSP page is the main view component of classic MVC, which is mainly the function of information display and controller processing result display.

In addition to the above, struts also provides a powerful Struts tag library to help users resolve display logic and to use the Actonform component to pass information to the control layer.

(2) control (Controller)

In the control layer, struts provides a controller component Actionservlet, which inherits from HttpServlet, and overloads the HttpServlet doget (), DoPost () method, which can accept HTTP responses and forward, It also provides the ability to forward mapping (mappings) using XML.

(3) Model

Models represent the processing of state and business logic, and in general Web applications, use JavaBean or EJBS to implement the business logic of the system. In struts, struts provides the action object to manage calls to the business logic, helping the user separate the business logic, meaning that struts itself does not implement the business logic, but can invoke the completed business logic. Struts Work Flow

The struts workflow is shown below (Figure 1.2).


Figure 1.2

Actionservlet is the core controller in struts, and all user requests must be handled by Actionservlet, The Struts-config.xml is the core configuration file in struts, where the user request URL and the Controller action mapping are configured in this file, and Actionservlet sends the user's request to the corresponding controller through this configuration file.

In the Struts Web application, when the Web application starts, Initializes the Actionservlet to load the Struts-config.xml configuration file when the Actionservlet is initialized, and the URL and controller mappings are stored in the Actionmapping object or other object when the load succeeds. When Actionservlet receives a user request, the user request is processed according to the following process.

(1) Actionservlet receives the user's request, will look for the matching actionmapping object according to the request URL, if the match fails, the user request URL path information is wrong, so the request path is returned invalid information, When the matching actionmapping is found, go to the next step.

(2) When Actionservlet finds a matching actionmapping object, it will determine the existence of the corresponding Actionform object according to the mapping information in the actionmapping. Creates a new

if no corresponding Actionform object exists.

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.