新建拦截器
package com.ujiuye.utils;
import com.ujiuye.pojo.Employee;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginHandlerInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String uri = request.getRequestURI();
if(uri.contains("login") || uri.contains("css")||uri.contains("js") ||uri.contains("fonts") ){
return true;
}
Employee employee=(Employee)request.getSession().getAttribute("USER_SESSION");
if(employee!=null){
return true;
}
request.getRequestDispatcher("/login").forward(request,response);
return false;
}
}
装配
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<!--拦截器的位置-->
<bean class=""/>
</mvc:interceptor>
</mvc:interceptors>