Disclaimer: All my articles are the compilation of online teaching videos, including Mad God Talk, Shang Silicon Valley, Dark Horse Programmer, etc., used as reference materials, without any commercial use, please refer to the majority of netizens, please do not spray ,Thank you.
1. Servlet working principle
Servlet is called by the web server. After the web server receives the browser request, it will process as follows:
2. Mapping problem
- A Servlet can specify a mapping path
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/dark1</url-pattern>
</servlet-mapping> - 一个Servlet可以指定多个映射路径
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/dark1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/dark2</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/dark3</url-pattern>
</servlet-mapping> - A servlet can specify the default request path (using wildcards ), and its priority is higher. If it conflicts with the homepage of the website, it will take precedence, so we generally don’t use
<servlet-mapping>
<servlet-name>helloServlet</servlet -name>
<url-pattern>/ </url-pattern>
</servlet-mapping> - A servlet can customize the suffix to implement request mapping
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Note: "* "The
priority of the project mapping path cannot be added before the number : the fixed mapping path has the highest priority, and the request that cannot find the mapping path will go to the default request path
3. Actual case, the custom error page is
in our previous On the basis of the section, create a new ErrorServlet class, the code is as follows:
configure web.xml to
start the Tomcat server for testing