After the web.xml file is configured, the browser accesses the servlet and reports an error 404.

After configuring the servlet and servlet-mapping parameters in the web.xml file under the web project, the solution to the 404 error is still reported when accessing with a browser:

The browser accesses the servlet: browser input address –> ip: port number/project name/path
insert image description here
is to match the value of url-pattern under the servlet-mapping configured in the web.xml file through the path under the project name, and then Use the value of servlet-name in servlet-mapping to match the value of servlet-name under servlet, and finally execute the class under servlet-class (limited class name);
insert image description here

Therefore, the following points should be paid attention to here:
1. The values ​​of the two servlet-names must be the same;

2. The value of servlet-class should be the corresponding limited class name, that is, the form of "package name.class name";
insert image description here
3. If the above two places are correct, it is generally a problem with the value of url-pattern, if it is url The reason for the -pattern value is that the console will display an error when tomcat starts:
insert image description here
you can add a slash / in front of the value of url-pattern, restart tomcat and then visit the browser.
insert image description here
Personal experience, I hope it can help you!

Guess you like

Origin blog.csdn.net/qq_43221829/article/details/101618848