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>