1. application.xml
<bean id="exceptionHandler" class="com.xing.handler.MyExceptionHandler"></bean>
2.package handler Class ...
1 public class MyExceptionHandler implements HandlerExceptionResolver { 2 @Override 3 public ModelAndView resolveException
(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Object o,
Exception e
)
{ 4 e.printStackTrace(); 5 ModelAndView modelAndView = new ModelAndView(); 6 modelAndView.setViewName("../error.jsp"); 7 modelAndView.addObject("msg","真的,没骗你"); 8 return modelAndView; 9 } 10 }
3.error.jsp
1 <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> 2 <html> 3 <head> 4 <title>Title</title> 5 </head> 6 <body> 7 出错了,服务器被修空调的偷走了 8 9 ${msg} 10 </body> 11 </html>