First, the development of JSP Dynamic Web pages, when we request a resource on the server through the browser, you may often encounter the bug reported 404 errors.
Problem analysis: The cause of this bug may be in a JSP Web page, or it may be inside a servlet. If the resource being accessed does not exist, a 404 error is generated.
(1) 404 errors may be a problem with the application itself. For example, the servlet name was incorrectly written without a normal deployment, web.xml deployment
(2) may also be a problem with the file, JSP file does not exist, the JSP name is wrong, or the servlet is not configured
There are several different representations of the servlet configuration parameter Url-pattern (servlet path), or several ways to access the servlet, which are presented in the form of code:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <display-name></display-name> <servlet> < Servlet-name>testservlet</servlet-name> <servlet-class>com.ccsu.zlweb.testservlet</ Servlet-class> </servlet> <!--default access, using a single slash ("/") as the Url-pattern parameter value--> <servlet-mapping> &L T;servlet-name>testservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping > <!--url-pattern parameter value is [*. extension] (extension is arbitrary) access <servlet-mapping> <SERVLET-NAME>TESTSERVLET</SERVL et-name> <url-pattern>/zl.ksgfj</url-pattern> </servlet-mapping>--> <!--path mapping access, url-p Attern parameter value is [/*/*], "*" is preferable to any value <servlet-mapping> <SERVLEt-name>testservlet</servlet-name> <url-pattern>/xdy/fhdsdjklf</url-pattern> </ Servlet-mapping>--> <!--exact matching path access, Url-pattern parameter values correspond to the path <servlet-mapping> <servlet-of the Web application's top and bottom roots Name>testservlet</servlet-name> <url-pattern>/servlet/TestServlet</url-pattern> </ Servlet-mapping>--> <!--Note that the default way to access, you need to delete this parameter, in addition to the index.jsp also deleted <welcome-file-list> <welcome-file
>index.jsp</welcome-file> </welcome-file-list>--> </web-app>
Three, 404 common cases of error collection of cotton:
"1" url-pattern label/parameter is incorrect, look at the Work\catalina\localhost directory of Tomcat, do not see the JSP compiled Java source files and class files. Such as:
"<url-pattern>/ShowContact</url-pattern>" mistakenly written "<servlet-url>/ShowContact</servlet-url>"
(PS: The web.xml files in the General IDE tool are generated automatically when you create the project, and the servlet configuration is automatically generated when you create the servlet.) Maybe sometimes we are in the configuration, and maybe accidentally changed something.
"2" web.xml when configuring the servlet, the servlet's name is wrong, inconsistent with the servlet file name (more common)
"3" Web.xml when configuring the servlet, the Servlet-class parameter (should be the full class name of the servlet) is not correct, that is, the full path of the servlet's class is incorrect
Let's share some of the shortcuts for getting the full servlet class name:
1. Open the servlet file where you need to configure the servlet to find the Servlet class name (public class decorated)
2, the cursor moved to the servlet class name, double-click it (then it will change color)
3, then the right mouse click, will appear a Drop-down menu, click "Copy Qualified Name" (similar to the copy of the operation)
4, and then back to configure its classpath, paste can (in fact, now anywhere paste will appear the full class name of the Servlet class).
(Action instance: double-click the class name of a servlet's file (Showcontact.java) showcontact---> Mouse right click it---> click "Copy qualified Name"---> Paste. The full class name "Cn.ccsu.web.ShowContact" of the servlet class will appear instead of the servlet's name.
Welcome-file-list is not configured in the "4" Web.xml or configured, but the Welcome-file parameter is wrong. That is, its parameter value *.jsp or *.htm or *.html's name is not the same as the name of the Web page file
"5" Could not find the resource, that is, the file does not exist (more commonly), that is, the resource name in the path is wrong, the wrong call, or the resource is not there.