Servlet code execution process

The order in which the request is received from the front desk, received in the background, and then the specified function is executed, and finally the return value is passed to the front desk.
Foreword:

  1. Web layer/Servlet layer (front and back-end interaction layer)
  2. Service layer (business layer: business code layer)
  3. Dao layer (persistence layer: logical code processing layer)
  4. Entity class (for example: User class, etc.)
  5. Tools (for example: Property, etc.)

The order of execution is as follows

1. First load the jsp file, jump according to the action in the form
Insert picture description here
2. Find the Servlet class corresponding to /Login in web.xml, and then jump to Servlet (UserServlet class)
Insert picture description here
3. After jumping to the Servlet, it will be based on the foreground Choose the corresponding method of the type

[Note:] The default submission method of the form without writing is get, but when we write a lot, we don’t know which one it is. Simply write it in the service, because the service can receive both the get type and the post type.
Insert picture description here

Insert picture description here
4. Jump to the corresponding method according to the value of the foreground, and then execute the corresponding business functions (for example: registration, login, etc.) of the Service layer (business layer).
Insert picture description here
Because Service is a business function interface, the actual jump to the Service is Implementation class-ServiceImpl class
Insert picture description here
5. Then jump from the Service layer to the corresponding method in the real logic code processing layer (Dao layer).
Insert picture description here
This is mainly to connect to the database, CRUD code, and the return value will be passed up if there is a return value.

6. The return value is passed back to the Servlet layer, and the Servlet can jump to different pages according to different return values. After
Insert picture description here
executing the page jump, a Servlet request-the end of the response

[Note: If you want to send the results of the query (multiple pieces) to the front desk, you can use collections and object storage, and pass the data to the front desk through the Session] For
details, please check https://blog.csdn.net/ qq_43288259/article/details/114643694

Guess you like

Origin blog.csdn.net/qq_43288259/article/details/114641035