在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>