STRUTS2---The history of a step-by-step production

Source: Internet
Author: User

struts2 The history of the production of one step at a1 JSP:

In the early Web applications are all static pages of HTML, JSP through the HTML file embedded Java script, the implementation of the page dynamic. HTML tags are responsible for layout and display appearance. Java code is responsible for extracting dynamic data and implementing business logic. For the simple application, this way can simplify the development difficulty, speed up the development speed, but also brings the problem, for larger projects, a large number of HTML and Java code mixed together, resulting in the page display logic and business logic confusion, the code is poor readability, maintenance is more difficult.

To separate the display and business logic, Sun developed two JSP development models MODEL1 and MODEL2.

2 Model1:

Use JSP and JavaBean technology to separate the page display from the business logic. JSP is responsible for page display, want to JavaBeans submit request, JavaBeans used to implement business logic and processing data.


It is not difficult to see that the JSP is responsible for processing the request and returning the processing results. All data is processed by JavaBeans and JSP is responsible for display. But it also has the disadvantage, for large-scale application system, in the page of a large number of Java statements to the page logic and business logic mixed, difficult to understand and maintain.

3 Model2

In Model1, the JSP page embeds the Process Control code and part of the logic processing code, extracting this part of the code and putting it into a separate role, which is the controller role, and such a Web schema is Model2. Model2 conforms to the MVC architecture pattern


The servlet acts as a controller, accepting requests and distributing them to will act JSP pages based on the requested information to produce a response. The servlet controller also generates an instance of JavaBeans based on the requirements of the JSP view and outputs it to the JSP. Using Model2 high-priced purchase, can be the page display, business logic processing and process control and clear area, JSP responsible for data display, JavaBeans responsible for carrying data and business logic processing, servlet responsible for process control. Front-end page designers and back-end Java developers develop synchronously, independently of each other.

4 web Framework--strutsWeb applications developed based on the MVC architecture pattern are prone to multiple controllers, and the handling of page navigation is complex when writing controllers. Through the analysis of the MVC-based framework Web application. Same as:(1) All requests have direct access to the controller, and the request is distributed by the director. (2) The controller instantiates the JavaBean object, has the JavaBean object to handle the business logic, and processes the data. (3) the controller renders the corresponding view to the user according to the result of the request processing. Different:(1) different processing units are applied to user request URL (2) data submitted by different forms requires different JavaBean objects to hold the data (3) The different result of request processing causes the controller to render different views to the user. based on these same differences, you can develop a web software that implements the entire invocation process in accordance with the MVC architecture and addresses the need for external configuration files where changes are required. With this flexible configuration, web software can be developed as a platform for other developers to use, and the web framework is born. Using a web framework eases our burden of developing Web applications, improves development efficiency, and lowers maintenance costs. There are many web frameworks, such as struts, WebWork, Spring MVC, Tapestry, JSF, WebPage3.0. The struts framework continues to be covered in the following sections.

4.1 struts1

structure diagram of 4.1.1 Struts1:


(1) Controller

STRUTS1 's controller has two parts, part is the Actionservlet, this class inherits from HttpServlet, has struts1 provides, as the central controller, it chooses the corresponding action class according to the user request to process the request. The other part is the action class, which is responsible for creating the business component, invoking the business component method to complete the business logic, written by the developer, the STRUTS1 framework provides the action base class, and we need to inherit the action base class when we write the action class.

(2) Model

The model is divided into 2 parts, part of the form bean object specified by the STRUTS1 framework, which is responsible for saving the submitted form data. The other part is the business component class that is written by the developer for the business logic of the system.

(3) View

Struts1 Framework supports JSTL, JSF, XSLT, etc.

4.1.2 Disadvantages1 Actionform Trouble2 Unit Test difficulty

4.2 struts2

Summarize:

According to the production of struts2, the emergence of a framework and the production and development of the technology are driven by the demand, as well as the existing problems arising from the technology.



STRUTS2---The history of a step-by-step production

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.