package com.basic.x01.system.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.basic.x01.base.BaseController; import com.basic.x01.systemMenu.MenuItem; import com.basic.x01.systemMenu.MenuUtil; /** * 统一的错误处理 * * @company 北京贝思科技术有限公司 * @author liuyajun, 8384503@qq.com * @date 2016年1月12日 * @time 下午11:27:12 */ @Controller public class FrameError extends BaseController{ public static final String FRAME_ERR = "FRAME-ERROR-STRING-MSG"; @RequestMapping("/error") public String error(HttpServletResponse res){ HttpServletRequest req = this.getRequest(); String errorMsg = (String)req.getAttribute(FRAME_ERR); String httpCode = this.getRequest().getParameter("httpCode"); if("404".equals(httpCode)){ errorMsg = "未找到页面"; } if(errorMsg ==null || errorMsg.trim().length()==0){ try{ Throwable exception = (Throwable) req.getAttribute( "javax.servlet.error.exception"); errorMsg = exception.getMessage(); if(errorMsg==null || errorMsg.trim().length()==0){ errorMsg = exception.toString(); } }catch(Throwable t){ } } if(errorMsg ==null || errorMsg.trim().length()==0){ errorMsg = "系统暂时发生一点错误,请稍后再试"; } req.setAttribute("errorMsg", errorMsg); res.setStatus(200); //作为正常处理 if(this.getLoingedUser() ==null){ //未登录 return "forward:/frame-jsp/unlogined-error.jsp"; }else{ //已登录 return loginedError(httpCode); } } public String loginedError(String httpCode){ if("404".equals(httpCode)) { String actionId = (String)this.getRequest().getAttribute( "currentRequestActionId"); if(actionId !=null){ MenuItem menu = MenuUtil.getMenuItemByActionId(actionId); if(menu !=null){ return "forward:/frame-jsp/logined-unfinish.jsp"; } } return "forward:/frame-jsp/logined-404.jsp"; } return "forward:/frame-jsp/logined-error.jsp"; } }