当前位置:网站首页>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 .
边栏推荐
- How to understand volatile
- Come to Xiamen! Online communication quota free registration
- AD20/Altium designer——过孔盖油
- MySQL string field to floating point field
- 【人脸识别】基于GoogleNet深度学习网络的人脸识别matlab仿真
- 你管这破玩意儿叫高可用?
- . NETCORE enables image scaling and cropping - based on imagesharp
- Partage de l'architecture du système de paiement du Groupe letv pour traiter 100 000 commandes simultanées élevées par seconde
- Team management | how to improve the thinking skills of technical leaders?
- Processing source code of spark executor execution results
猜你喜欢

快速掌握 ASP.NET 身份认证框架 Identity - 用户注册

Application description of DAP fact table processing summary function

Hello playwright: (7) simulate keyboard and mouse

Qt Notes - qmap Custom key

client-go gin的简单整合十-Update

DAP事实表加工汇总功能应用说明

新手必会的静态站点生成器——Gridsome
![[step 1 of advanced automated testing] 1 minute to introduce you to automated testing](/img/00/9647d552749092954a91bd84307773.png)
[step 1 of advanced automated testing] 1 minute to introduce you to automated testing

Gridhome, a must-have static site generator for beginners

Come to Xiamen! Online communication quota free registration
随机推荐
WPF效果第一百九十篇之再耍ListBox
Scala for derivation: the ability to define a value in the first part of a for expression and use it in subsequent (outer) expressions
[mysql] data synchronization prompt: specified key was too long; max key length is 767 bytes
数据库mysql 主从方案
UI自动化定位利器-xpath实战
DAP事实表加工汇总功能应用说明
What should I do if I can't hear a sound during a video conference?
On the closure function of Scala
网页制作存在的一些难点
Ad20/altium Designer - oil for manhole cover
Examples of MySQL account addition, deletion, modification, data import and export commands
QT notes qmap user defined key
JMeter use case
Purchase guide - how to purchase a high-quality conference tablet, these aspects must be compared
[face recognition] matlab simulation of face recognition based on googlenet deep learning network
High availability ResourceManager
mysql指令执行sql文件
同花顺软件是什么?手机开户安全么?
Interview shock 58: Six differences among truncate, delete and drop!
【阿里云服务器-安装mysql的5.6版本安装,重装】