There are two ways to configure servlet, namely deploying servlet in traditional web.xml document and deploying servlet in annotation mode. Let’s first learn how to deploy servlet in
annotation mode . Deploy servlet in annotation mode:
First, create a class in the idea project space. , If this step is still not possible, I suggest reading this blog:
[ https://blog.51cto.com/14954398/2542444 ]()
Then add the Servlet class after the class name, as follows:
rewrite all classes in the Servlet, as follows:
Finally, write the front-end page to be connected above the class name, as follows:
When sending a request from the browser, it will directly look for the corresponding url address after @WebServlet, call and execute the corresponding servlet!
Deploy the servle in the traditional web.xml document:
first find the web.xml document that needs to be configured:
double-click to enter the web.xml document and write the mapping code:
to sum up:
Editing the xml file:
Advantages: If there are multiple servlets in the same project, it is easy to manage and modify
Disadvantages: manual configuration files, easy to cause errors, too high repetition, poor readability
Annotation deployment:
advantages: fast and concise, IDE will automatically
Disadvantages of creating annotations : if there are many servlet files, it is difficult to control a single servlet