当前位置:网站首页>JSP development model

JSP development model

2022-06-11 07:46:00 Nagisa siku

JSP Development model

Concept

JSP The development model is JSP Model, stay Web In development , To make it easier to use JSP technology ,Sun Company as JSP Technology provides two development models :JSP Model1 and JSP Model2.JSP Model1 Simple and light , Suitable for small Web Rapid development of the project ;JSP Model2 The model is in JSP Model1 On the basis of , It provides clearer code layering , It is more suitable for large-scale projects developed by multiple people Web project , The actual development process can be based on the project requirements , Choose the right model .
JSP Model1
use JSP+JavaBean Technology , Separate page display from business logic . among ,JSP Realize process control and page display ,JavaBean Objects encapsulate data and business logic .JSP Model1 The working principle of is shown in the figure below .

JSP Development mode ( Four patterns )
pure JSP Programming

stay JSP In programming mode , By applying the JSP Script flags in , Can be directly in JSP Various functions are realized in the page . Although this model is easy to implement , however , Its disadvantages are also very obvious . Because most of Java Code and the HTML Code mixed up , It will bring many difficulties to the maintenance and debugging of the program , And it is difficult to clarify the complete program structure .

This is like planning and managing a large enterprise , If all employees responsible for different tasks are arranged to work together , It is bound to cause chaos in the company 、 Difficult to manage and many other hidden dangers . So , pure JSP Page programming mode cannot be applied to large-scale applications 、 Medium or even small JSP Web In application development

JSP+JavaBean Programming

JSP+JavaBean The programming mode is JSP Program development is one of the classic design patterns , Suitable for the development of small or medium-sized websites . utilize JavaBean technology , It can easily complete some business logic operations , For example, database connection 、 User login and logout, etc .

JavaBean Is a person who follows certain rules Java class , In the development of the program , Encapsulate the business logic to be carried out into this class , stay JSP On the page , This class is called through the action tag , To execute the business logic . At this time JSP In addition to the control of some processes , It is mainly used for page display , and JavaBean Is responsible for the processing of business logic .
It can be seen that ,JSP+JavaBean The design pattern has a relatively clear program structure , stay JSP The initial stage of Technology , This model has been widely used .
The user requests the server through the client browser .
The server calls after receiving the user request. JSP page .
stay JSP Call in page JavaBean.
stay JavaBean Connect and operate the database in , Or implement other business logic .
JavaBean Return the result of execution to JSP+ page .
The server reads JSP Content in page ( Combine static content with dynamic content in the page ).
The server returns the final result to the client browser for display .

JSP+JavaBean+Servlet Programming
JSP+JavaBean Although the design pattern has separated the business logic of the website from the display page , But in this mode JSP Not only to control most of the processes in the program , But also responsible for the display of the page , So it is still not an ideal design pattern .

stay JSP+JavaBean Add... Based on the design pattern Servlet To implement the control layer in the program , Is a good choice . In this mode , from Servlet To execute the business logic and be responsible for the process control of the program ,JavaBean Components implement business logic , Act as a model of ,JSP Used for page display . It can be seen that , This model makes the hierarchical relationship in the program more obvious , The division of labor of each component is also very clear . chart 2 Represents the process of processing the client's request in this mode .

MVC Pattern

MVC(Model-View-Controller, Model - View - controller ) Is a programming concept , It applies to both simple and complex programs . Using this pattern , The application to be developed can be broken down into three separate parts : Model 、 Views and controllers .

This design pattern is proposed mainly because of the code used to complete the task in the application ( Model , Also known as “ Business logic ”) Usually the relatively stable part of the program , And will be reused , The page where the program interacts with the user ( View ), But it often changes .

If you have to change the business logic code because you need to update the page , Or write business logic code repeatedly when applying the same function in different modules , It will not only reduce the overall process of program development , And it will make the program difficult to maintain . therefore , Separate business logic code from appearance rendering , It will be easier to improve the program according to the change of requirements

MVC Design patterns
MVC frame

classic MVC In the pattern ,M The business model ,V User interface ,C Controller , Use MVC The goal is to M and V Implementation code separation of , So that the same program can use different forms of expression . among ,View The definition of , It's the user interface .

brief introduction

MVC Initially present in the desktop program ,M The business model ,V User interface ,C Controller , Use MVC The goal is to M and V Implementation code separation of , So that the same program can use different forms of expression . For example, a batch of statistical data can be used as a histogram 、 Pie chart to show .C The purpose of existence is to ensure that M and V Synchronization of , once M change ,V It should be updated synchronously . Model - View - controller (MVC) yes Xerox PARC It was a programming language in the 1980s Smalltalk-80 A software design pattern invented , Has been widely used . Later recommended as Oracle its Sun company Java EE Design mode of the platform , And it's used more and more ColdFusion and PHP Welcome to developers . Model - View - Controller mode is a useful toolbox , It has many advantages , But there are also some disadvantages .

MVC Programming model

V namely View A view is an interface that users see and interact with . For example, by html Elements of the web interface , Or the client interface of the software .MVC One of the benefits is that it can handle many different views for the application . There's no real processing in the view , It's just a way to output data and allow users to operate .
M namely model A model is a model that represents business rules . stay MVC Of the three components of , The model has the most processing tasks . The data returned by the model is neutral , The model has nothing to do with the data format , Such a model can provide data for multiple views , Because the code applied to the model needs only to be written once, it can be reused by multiple views , So it reduces the repeatability of the code .
C namely controller Controller means that the controller accepts the user's input and calls the model and view to complete the user's requirements , The controller itself does not output anything or do any processing . It just receives the request and decides which model component to call to process the request , Then determine which view to use to display the returned data .

原网站

版权声明
本文为[Nagisa siku]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020518498518.html