Java B/S Development Mode)
As the most popular architecture model today, B/S has also been recognized by developers and customers, and its development model is constantly evolving, here I will review and discuss the development mode of Java B/S, which is also a summary of the development mode of Java B/S.
Jsp + Jdbc
One of the simplest development modes in B/S development is page + logic processing, which is mapped to Jsp + Jdbc, which is technically reflected, in this kind of implementation, the View layer, that is, the jsp page, is responsible for data display and logic processing. Combined with jdbc, data persistence is achieved. In small projects, people do find this method the most convenient, but in complex projects and projects with changing requirements, people gradually find that this method has caused many problems, the first is debugging. Think about how difficult it is to troubleshoot errors on a jsp page, and the second is the modification. In order to meet the user's needs, you need to modify a lot of pages. In many cases, it takes a long time for you to remember what is going on, let alone what will happen if people flow, at the same time, it also brings about development efficiency issues. Due to the lack of adequate debugging support, more skilled developers are required to complete the process quickly, for general personnel, certain adaptation and learning processes are required. Of course, some errors may occur when some code is accidentally copied when the interface is modified, the biggest problem may be reuse. Generally, N more identical codes are copied on the page. To sum up, there are several major problems in this mode:
1. debugging problems.
2. maintenance problems, display and logic processing lead to difficulties in modifying the display. As for code modification, the previous debugging problems lead to difficulties, at the same time, because the logic is all on the page, it takes some time for the successor to understand.
3. code reusability.
But it also has advantages, that is, it can be quickly used, but because the debugging and maintenance problems are indeed too large, so now it is basically no longer used this method.
Jsp + JavaBean
After going through the jsp + jdbc stage, we began to consider how to solve the above three problems. At this time, we came into being technical systems such as JSP + JavaBean, in this system, jsp pages are used to display and receive page requests, and corresponding JavaBean is called to complete logical processing. After obtaining the processed data, it is displayed on the corresponding page. In such a technical system, because the logic is completed by JavaBean, You can debug it, and the code reusability is also improved to a certain extent. At the beginning, using such a technical system was indeed much better than using jsp + jdbc. However, with the increasing use of the technology, the problem was gradually discovered, that is to say, you need to write a response to the page request data on the page. You have to call the corresponding javabean according to the request and transfer it to the corresponding page according to the processing result of the javabean, this also causes the trouble of modification. After all, it is to modify these logics on the page. In summary, there are major problems in this mode:
1. code reusability and maintenance. However, the code reusability here is different from that of jsp + jdbc. In the logic processing section, it can be reused now, however, on each page, you have to repeatedly write parameters to obtain the page request, call the Model, and forward the Page Based on the processing result of the Model, in this case, you need to search for the change, resulting in complicated maintenance.
2. The system structure is unclear. After all, it is still the process of controlling the entire response page event on the page. At this time, many pages have identical jsp code, and it is still inconvenient to control the code on the page, for example, for the call of JavaBean, and because the data of obtaining the javabean needs to be forwarded, it is usually to add the code that controls the event processing process on the final display page, there is no real separation of display and processing.
Similarly, it separates display and business logic processing, enhances debugging and maintainability, and is easy to use. It is still one of the optional solutions for small projects.
MVC Framework-based
After going through the Jsp + JavaBean above, in fact, the most important thing we need now is to have something between jsp and javabean to automatically encapsulate the page request data, call the corresponding javabean according to the request, and return the corresponding result according to the processing result of the javabean. view, with this idea, we found that the MVC idea in smalltalk is very suitable for this scenario, So we introduced the MVC idea in Java B/S development, here, we also briefly introduce the MVC idea. MVC emphasizes the separation of View and Model. View faces the Controller, which is responsible for interacting with the Model, view is only responsible for processing the display page and display logic. The display logic refers to the processing of display such as the first line to display blue and the second line to display red, the Controller is responsible for receiving page requests, encapsulating the request data, calling the corresponding Model based on the request for logical processing, and returning the result data to the Controller and Controlle after Model processing. R calls the corresponding View based on the data and passes the data to the View. The View is responsible for integrating and finally displaying the data. The advantages brought by MVC are clearly reflected. Based on this MVC Framework, developers can develop according to a fixed pattern and regulate the entire development process, this improves the quality and clarity of the system structure, and ensures the separation of View/Model, so that a Model can be used for View in multiple display forms. All you need is to change the View and Controller.
According to the MVC idea, the most likely implementation solution is jsp + servlet + javabean, where jsp corresponds to View, servlet corresponds to Controller, and javabean corresponds to Model, the servlet can be used to encapsulate the page data request object HttpServletRequest, which saves the effort of encapsulating the page request data, as a Controller, you also need to call the corresponding javabean according to the request. The simplest way is to directly call the corresponding bean for execution in the Servlet based on a logic (such as reflection or interface, then, the HttpServletRequest and HttpServletResponse parameters are passed into the javabean for processing. The javabean obtains the request data from HttpServletRequest and puts the returned result data into HttpServletResponse. The Controller takes over the processing. At this time, the servlet of the Controller will return the corresponding page based on the processing result. When using this model, people gradually discover a problem, that is, as the jsp and javabean changes, the controller is constantly modified. You need to modify the calling of the corresponding javabean and forwarding the corresponding page. To solve this problem, the first thought is to separate the steps for calling the corresponding javabean according to the request. At this time, the front controller + application controller Method in the design mode is used. The front controller is responsible for accepting and encapsulating page requests, at the same time, this data object is passed to the application controller, and the application controller is responsible for calling the corresponding bean. Such design follows a design principle, that is, the responsibility is single, generally, the mode for implementing application controller is Co. In this case, the structure of the MVC Framework has evolved into view + controller (front + application) + model.
After completing the above evolution, I slowly found another problem, that is, the model relies on httpservletrequest. In this case, a problem is that the model cannot be tested, and the server must be continuously restarted for testing, of course, the development at the same time is the refinement of the model Layer, which is refined into the action Layer + Domain Model Layer + Persistent Layer used to respond to page requests. Here we will not discuss the following layers, as the MVC Framework, it does not matter how the Model layer handles the process.
I also found another problem, that is, changes often affect the controller modification. So I introduced a solution using the configuration file to compile the action configuration file, in the configuration file, control the returned results of the action to be transferred to the corresponding View. In this way, you only need to change the configuration file in the future to ensure the stability of the Controller, this is a key factor in the typical design. The separation of changes and non-changes minimizes the impact of changes.
However, after the above configuration file is introduced, the problem is gradually discovered, that is, handwritten configuration files are always prone to various problems, at this time, the idea of using a graphical interface to generate a configuration file was introduced, which created the birth of page flow. Of course, this is only a small part of the page flow function.
Of course, the development of MVC has also led to the development of other related technologies, such as asynchronous request/response modes (ajax, amowa, ^_^.
After accepting the MVC idea, the MVC Framework in the open-source community has sprung up. Well-known such frameworks include struts, webwork, and spring mvc, all of these MVC frameworks have basically met the needs of the evolution of MVC ideas mentioned above. Of course, even if the current MVC Framework does, however, when using the MVC Framework, we often start to violate the basic elements of the MVC idea, that is, maintaining the View is only the principle of View, therefore, we recommend that you use Velocity in View as a View to keep the View clean. The development of any technology is gradual, when we don't stand at that height, we don't know what kind of mountain we are in front of. So what are the problems we lack now? What are the shortcomings in the current MVC Framework? This is worth thinking about.