History
Struts history. JSP has undergone JSPModel1 and JSPModel2 stages. JSPModel1 just like PHP today, each file is mixed with business logic and HTML code, and each JSP interacts directly with the database. This model is very limited and has poor code reuse. Later, an improved version of JSPModel1 is added, which adds JavaBean. JSP files need to access the database indirectly through JavaBean. There are three techniques used in JSPModel2: Servlet, JavaBean, JSP. The servlet acts as a controller, takes control of the process, dispatches requests, and invokes JavaBean and JSPs. JavaBean is responsible for interacting with the database. JSP only does the display of pages, which is used to generate dynamic Web pages. JSPModel2 has begun to show the idea of MVC.
Brief introduction
Struts is a web framework, and the problem that the web framework needs to address is the HTTP stateless and text-based two issues. Resolving stateless issues can be managed through a cookie or session, both of which have been resolved in the servlet. Text-based issues are issues that struts should focus on. HTTP is a text protocol, which is a tedious process to convert to data structures in Java and method invocations. With the struts framework, these tedious things do not need to be dealt with on their own.
STRUTS2 is not a framework for improvement on the basis of STRUTS1, but a new framework based on WebWork. But if you are already familiar with Struts1, then Struts2 learning is very easy.
The MVC in struts. The controller is Filterdispatcher, also known as the front-end controller, because it receives the request first. Its essence is a servlet that allows Struts2 to operate as long as it is configured to flow HTTP requests to Filterdispatcher. In the latest version of Struts, Filterdispatcher has been renamed Strutsprepareandexecutefilter, with a clearer name. The model (action) is a model of the thing itself, the business logic, the data storage should be put in the models. A view is a result, something the client can see. The Web container first finds the XML, and the developer first assigns the Filterdispatcher to XML, which allows struts to execute it.
The entire workflow for STRUTS2 is as follows:
It looks very concise, and the entire struts framework needs to know what the above is all about.
Java Web framework: Struts2 Introduction