In the past, I was not familiar with Java Development. I always thought that the JavaBean and Servlet are amazing, strange, and complicated. Now I have read a very basic JSP book, I have finally understood them.
Javabean is a Java class, except that it has the getxxx () and setxxx () methods, and. the get/set in net is similar, or it must be a public class with a non-argument constructor. In JSP development, it can be said to process some logic, such as computing, and the JSP page uses <JSP: usebean...> this label references this JavaBean class and displays the processing result and some information on the JSP page. It can be said that the background and foreground are basically separated.
Servlet is not specifically developed for HTTP, but it seems that it is only used here. It mainly applies the httpservlet class. Doget ()/doput ()/dopost ()... Wait for the doxxx method, and there is a service () method. These functions have only two parameters, one of which is httpservletrequest and httpservletresponse, reques is generated when the web server responds to the HTTP request of the browser and closes the request information in httpservletrequest. It also creates an httpservletresponse object and provides the servlet with the response information.
The Service () method has been implemented in httpservlet. It calls different doxxx () Methods Based on Different HTTP requests. At the same time, we do not directly call the doxxx () method, generally, we only need to override the doxxx () method. Httpservlet then automatically calls the Service () method and calls the doxxx () method by itself through the Service () method. In programming, we mainly cover the doget () and deput () methods.
The most important thing here is that the Web server encapsulates the client request information to httpservletrequest and creates httpservletresponse. Then we can get the corresponding request information and output the corresponding response.