Servlet is a server-side Java application that is platform and protocol independent and can generate dynamic Web pages. It acts as the middle layer between client requests (web browsers or other HTTP client programs) and server responses (databases or applications on the HTTP server). Servlet is a server-side Java application located inside the Web server. Unlike traditional Java applications launched from the command line, Servlet is loaded by the Web server, which must contain a Java virtual machine that supports Servlet.
In layman’s terms:
1. For example, you enter your name and password on a web page, and then click submit. At this time, the page will jump (the jump methods include post and get).
2. Where to jump to? Configure your jump through the web.xml file. Generally, you jump to the servlet for processing.
3. To put it bluntly, servlet is a java class that inherits HttpServlet and mainly has doGet and doPost methods. If you write the get method jump in the page code, then run the code in the doGet method in the servlet ( post is the same).
4. The code in doGet handles the operation. Generally, it first uses a specific method to obtain the name and password submitted on the page, and then processes it (determines whether it is legal, etc.). After processing, it is decided to directly display the information. Or jump to other pages.
Servlet is a java class that accepts page information and then performs logical processing.
Servlet is used for Web development and serves as the control layer to process user request information. Servlet is the foundation of BS development. Understanding Servlet will be of great help to you in the future to learn JSP and the subsequent Struts2 framework. When working normally, Servlet is not used much, and Struts2 is used to replace the functions completed by Servlet.
You can understand it this way, when you click on a link on a web page, a request will be submitted to the server. This request is divided into two types, one is a post request and the other is a get request. The corresponding Servlet processing request also has a doget() and dopost() methods. After the Servlet processes the results, it will put the processed information in different scopes and return to the web page for display.
The above is the detailed content of What is java servlet. For more information, please follow other related articles on the PHP Chinese website!