在tomcat的web.xml中聲明異常和錯誤頁面

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章