1、在jsp頁面中設置
<%@ page errorPage="/WEB-INF/error.jsp" %>
錯誤頁面設置,
<%@ page isErrorPage="true"%> <%=exception%>//只有設置了isErrorPage="true",才能用exception內置對象
2、可以統一在web.xml進行設置
根據錯誤碼設置 <error-page> <error-code>404</error-code> <location>/WEB-INF/error.jsp</location> </error-page> 根據異常分類設置 <error-page> <exception-type>java.lang.ArithmeticException</exception-type> <location>/WEB-INF/error.jsp</location> </error-page>