Peter20150926 2018-03-19 06:57 采纳率: 78.3%
浏览 1554
已结题

拦截器退出登录 判断跳转的问题...求教

首先运行项目(index.jsp):

  ![图片说明](https://img-ask.csdn.net/upload/201803/19/1521442431_934828.png)

##后台Controller处理请求
图片说明

跳到主页

图片说明

下面就是登录进入主页,如进入管理员页面,并且点击退出 :

图片说明

# 拦截器代码:

图片说明

但是一旦退出到home页 页面就是空了........
不晓得咋的回事.....求教这个拦截器咋写

  • 写回答

2条回答 默认 最新

  • Peter20150926 2018-03-19 06:58
    关注
    @Override
    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
        // TODO Auto-generated method stub
    
    }
    
    @Override
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
    
    
    }
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler) throws Exception {
    
        //获取Session  
        HttpSession session = request.getSession();  
        String username = (String)session.getAttribute("username");  
          System.out.println(username);
        if(username != null){  
            return true;  
        }  
        //不符合条件的,跳转到登录界面  
        String path=request.getContextPath()+"/front/home";
        response.sendRedirect(path);
        return false;  
    }
    
    评论

报告相同问题?