If you don’t use a framework to write a system by hand, you don’t have to use the MVC structure at all. Why do you have to stick to what a controller is? Remember that all servers only do the following work: “Receive some data, do calculations, and return some data. ”, if it can meet this requirement, your system will be formed. There is no need to stick to any structure
Servlet has only two functions, receiving requests and forwarding. Receive form data, encapsulate it into corresponding objects, and then pass it to service
First of all, you need to understand a few points. The framework is also encapsulated on the basis of Servlet and becomes easier to use. Your idea is right, but I suggest you take a look at the Servlet API and you will understand it immediately. Let me give you some ideas. After the Servlet is started, tomcat is responsible for monitoring http requests and forwarding them to your application. Every time a new request comes, the service method in the Servlet you wrote will be called, and then the doGet, doPost and other methods are called according to the content of the request, so you only need to inherit the Servlet and override these methods. accomplish. As for the layering underneath. It has nothing to do with Servlet. You have to understand that the purpose of your layering is to reduce coupling. If you need help, please send me a private message. Recently, I am imitating Tomcat to build a web server, so I know a lot about this area.
Your idea is the layered idea in the framework, and there is nothing wrong with doing so.
If you don’t use a framework to write a system by hand, you don’t have to use the MVC structure at all. Why do you have to stick to what a controller is? Remember that all servers only do the following work: “Receive some data, do calculations, and return some data. ”, if it can meet this requirement, your system will be formed. There is no need to stick to any structure
Servlet has only two functions, receiving requests and forwarding. Receive form data, encapsulate it into corresponding objects, and then pass it to service
First of all, you need to understand a few points. The framework is also encapsulated on the basis of Servlet and becomes easier to use.
Your idea is right, but I suggest you take a look at the Servlet API and you will understand it immediately.
Let me give you some ideas. After the Servlet is started, tomcat is responsible for monitoring http requests and forwarding them to your application.
Every time a new request comes, the service method in the Servlet you wrote will be called, and then the doGet, doPost and other methods are called according to the content of the request, so you only need to inherit the Servlet and override these methods. accomplish. As for the layering underneath. It has nothing to do with Servlet. You have to understand that the purpose of your layering is to reduce coupling.
If you need help, please send me a private message. Recently, I am imitating Tomcat to build a web server, so I know a lot about this area.