短视频直播系统,软件自带的拦截器,拦截功能实现的相关代码
核心源码
LoginInteceptor
package com.wanshi.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//1.对登录,注册,风格直接放行
//获取请求的uri地址
String uri = request.getRequestURI();
if (uri.contains("login")) {
return true;
}
//2.进行session验证
Object user = request.getSession().getAttribute("user");
if (user == null) {
request.getRequestDispatcher("/WEB-INF/pages/login.jsp")
.forward(request, response);
return false;
}
return true;
}
}
spring-mvc配置文件增加拦截器配置
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean id="loginInterceptor" class="com.wanshi.interceptor.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
以上就是短视频直播系统,软件自带的拦截器,拦截功能实现的相关代码, 更多内容欢迎关注之后的文章