Просмотр исходного кода

统一异常处理增加ajax区分

shuzheng 9 лет назад
Родитель
Сommit
df069002ce

+ 3 - 0
zheng-common/src/main/java/com/zheng/common/base/BaseController.java

@@ -32,6 +32,9 @@ public abstract class BaseController {
 	public String exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
 		_log.error("统一异常处理:", exception);
 		request.setAttribute("ex", exception);
+		if (null != request.getHeader("X-Requested-With") && request.getHeader("X-Requested-With").equalsIgnoreCase("XMLHttpRequest")) {
+			request.setAttribute("requestHeader", "ajax");
+		}
 		// shiro没有权限异常
 		if (exception instanceof UnauthorizedException) {
 			return "/403";

+ 6 - 1
zheng-upms/zheng-upms-server/src/main/webapp/WEB-INF/jsp/403.jsp

@@ -12,10 +12,15 @@
 <title><spring:message code="403"/></title>
 </head>
 <body>
+<c:if test="${requestHeader == 'ajax'}">
+    <h5 style="padding-bottom: 10px;">没有权限!</h5>
+</c:if>
+<c:if test="${requestHeader != 'ajax'}">
 <% Exception e = (Exception)request.getAttribute("ex"); %>
 <h2>错误: <%= e.getClass().getSimpleName()%></h2>
 <hr />
 <h5>错误描述:</h5>
-<%= e.getMessage()%>
+<p><%= e.getMessage()%></p>
+</c:if>
 </body>
 </html>