Two mapping methods and advantages and disadvantages of servlet in idea

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 ]()
Two mapping methods and advantages and disadvantages of servlet in idea

Then add the Servlet class after the class name, as follows:
Two mapping methods and advantages and disadvantages of servlet in idea
rewrite all classes in the Servlet, as follows:
Two mapping methods and advantages and disadvantages of servlet in idea

Finally, write the front-end page to be connected above the class name, as follows:
Two mapping methods and advantages and disadvantages of servlet in idea


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:
Two mapping methods and advantages and disadvantages of servlet in idea
double-click to enter the web.xml document and write the mapping code:
Two mapping methods and advantages and disadvantages of servlet in idea

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

Guess you like

Origin blog.51cto.com/14954398/2542875