拦截器(拦截跳转):

项目中使用:

package com.xn.bmpos.manager.bmposmanager.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
/**
 * 登录拦截器
 * @author soft01
 *
 */


public class LoginInterceptor implements HandlerInterceptor {
   
   @Override
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
         throws Exception {
             HttpSession session = request.getSession();
             if(session.getAttribute("uid")==null) {
                System.out.println("未登录!");
                response.sendRedirect("../web/login.html");
                return false;
             }else {
                return true;
             }
            
   }
   
}

你可能感兴趣的:(个人随笔)