@ExceptionHandler(value = Exception.class)
public void exceptionHandler(HttpServletRequest request, HttpServletResponse response,
Exception e, Model model) throws Exception {
if (isAjax(request)) {
// 向response中写json数据
response.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter writer = response.getWriter();
writer.write(gson.toJson(JsonResult.errorException(e.getMessage())));
} else {
request.setAttribute("exception", e);
request.setAttribute("url", request.getRequestURL());
request.getRequestDispatcher("/templates/error.html").forward(request,
response);
}
}