在web.xml中增加如下红色的内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<error-page>
<error-code>404</error-code>
<location>/pageNotFound.html</location>
</error-page>
</web-app>
说明:指定错误代码为404是,调用/pageNotFound.html
也可以将location指定到一个jsp上:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>