liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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";
    }
}