当前位置:网站首页>Development mode of JSP learning
Development mode of JSP learning
2022-06-22 17:27:00 【xiao_ zhu_ ting_ feng】
JSP Development mode ( Four patterns )
JSP Program development modes include JSP Programming 、JSP+JavaBean Programming 、JSP+JavaBean+Servlet Programming 、MVC Pattern .
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 Classic program development Design patterns One of , 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 .
chart 1 Represents the process of processing the client's request in this mode , The relevant instructions are as follows .
- 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 .

chart 1 JSP+JavaBean Design patterns
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 .

chart 2 JSP+JavaBean+Servlet Design patterns
chart 2 In the mode shown , The steps are described below .
- The user requests the server through the client browser .
- The server calls after receiving the user request. Servlet.
- Servlet Call... According to the user's request JavaBean Deal with business .
- stay JavaBean Connect and operate the database in , Or implement other business logic .
- JavaBean Return the result Servlet, stay Servlet Save the results to the request object .
- from Servlet Forward the request 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 .
but JSP+JavaBean+Servlet There are also shortcomings in the model . This pattern follows MVC Design patterns ,MVC Just an abstract design concept , It breaks down the application to be developed into three separate parts : Model (Model)、 View (View) And controller (Controller).
Although it is used to realize MVC The techniques of design patterns may all be the same , But each company has its own MVC framework . in other words , These companies are used to realize their own MVC The technology applied by the architecture may be JSP、Servlet And JavaBean, But their process and design are different , So engineers need to spend more time understanding .
From the perspective of project development , Because you need to design MVC Format and method of data exchange between objects , So it takes more time to design the system .
Use JSP+JavaBean+Servlet Pattern for project development , You can choose an implementation MVC A ready-made framework for patterns , Develop on the basis of this framework , It can greatly save development time , You'll get twice the result with half the effort . at present , There are many ready-made MVC frame , for example Struts frame .
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 The model of the pattern is shown in Figure 3 Shown .

chart 3 MVC Models of patterns
Model( Model ):MVC In the pattern Model( Model ) It refers to the code of business logic , It is the part of the application that is really used to complete the task .
View( View ): The view is actually the interface between the program and the user , Users can see its existence . Views can have certain functions , And shall abide by the constraints imposed on it . In the view , It should not contain code for data processing , Business logic code .
Controller( controller ): The controller is mainly used to control user requests and respond . It is based on the user's request , Select a model or modify a model , And decide what view to return .
边栏推荐
- Seeing the big from the small: a simple example of domain modeling, understanding "domain driven".
- Description of new features and changes in ABP Framework version 5.3.0
- Xshell 7 (SSH Remote Terminal tool) v7.0.0109 official Chinese Version (with file + installation tutorial)
- How to solve the problem of database?
- 可能是全网最全的Matplotlib可视化教程
- Hello playwright: (7) simulate keyboard and mouse
- Kibana+elk cluster log processing
- 网传学习通1.7亿密码泄露!有什么补救措施?
- 来厦门了!线上交流限额免费报名中
- STM32系列(HAL库)——F103C8T6硬件SPI点亮带字库OLED屏
猜你喜欢

社会担当 广汽本田“梦想童行”倡导儿童道路交通安全

快速掌握 ASP.NET 身份认证框架 Identity - 登录与登出

System throughput, TPS (QPS), user concurrency, performance test concepts and formulas

Kibana+elk cluster log processing

It may be the most comprehensive Matplotlib visualization tutorial in the whole network

Seeing the big from the small: a simple example of domain modeling, understanding "domain driven".

What should I do if I can't hear a sound during a video conference?

Apache ShardingSphere 一文读懂

Tried several report tools, and finally found a report based on Net 6

Quartus Prime 18.0软件安装包和安装教程
随机推荐
Principle of synchronized implementation
Tried several report tools, and finally found a report based on Net 6
Mybaits:常用数据库操作(东软的操作)
What is a flush? Is online account opening safe?
Spark's NaiveBayes Chinese text classification
Description of new features and changes in ABP Framework version 5.3.0
Analysis of the read data source code of spark shuffle
JMeter use case
Vs2017 solution to not displaying qstring value in debugging status
Analysis of the writer source code of spark shuffle
同花顺软件是什么?手机开户安全么?
Call CMD process communication
Redis implements the correct posture of the delay queue
170million passwords of Netcom learning link have been leaked! What are the remedies?
Redis实现延迟队列的正确姿势
Blazor University (31) form - Validation
Read Apache shardingsphere
Hello Playwright:(7)模拟键盘和鼠标
CMB model 23 ukey is not recognized on win7
Come to Xiamen! Online communication quota free registration