当前位置:网站首页>SSM项目使用过滤器实现登录监听
SSM项目使用过滤器实现登录监听
2022-07-27 16:21:00 【qq_42042158】
SSM项目中配置过滤器实现登录监听,未登录不能访问某些页面
- 编写一个过滤器的类实现Filter接口,在实现方法中添加具体操作
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
public class LoginFilter implements Filter {
//初始化:web服务器启动时就会初始化
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response =(HttpServletResponse)servletResponse;
HttpSession session = request.getSession();
if (session.getAttribute("loginuser")==null){
response.sendRedirect(request.getContextPath()+"/login/adminLogin.jsp");
}else {
//让请求继续往下走,如果不写,到这里请求就会被拦截
filterChain.doFilter(servletRequest,servletResponse);
}
}
//销毁,web服务器关闭的时候会销毁
@Override
public void destroy() {
}
- 在web.xml中配置过滤器
<filter>
<filter-name>LoginFilter</filter-name>
<!-- 实现filter接口的类 -->
<filter-class>edu.gnnu.newcomer.aop.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<!-- 要过滤的页面 -->
<url-pattern>/manager/*</url-pattern>
</filter-mapping>
配置过后这些页面都会先经过过滤器,如果不满足过滤器中的条件则执行过滤器中定义的操作
边栏推荐
- 全身多功能按摩仪芯片-DLTAP602SD
- 飞机大战敌机出场
- Typeerror: conv2d(): argument 'padding' (position 5) must be multiple of ints, not STR [error]
- The combination of text and words perfectly explains the implementation process of MySQL logical backup
- Leetcode brushes questions the next day
- Talking about JVM (frequent interview)
- Canvas draws graphics according to coordinate points
- MySQL 04 advanced query (II)
- 微信支付及支付回调
- MySQL 02 初体验
猜你喜欢

低噪负离子风扇触摸IC

express get/post/delete...请求

Must the MySQL query column be consistent with the group by field?

USB充电式暖手宝芯片-DLTAP602SC-杰力科创

全身多功能按摩仪芯片-DLTAP602SD
![[NPM] the](/img/ae/efccefae0323a1f6a425523e01d2ac.png)
[NPM] the "NPM" item cannot be recognized as the name of cmdlets, functions, script files or runnable programs. Please check the spelling of the name. If the path is included, make sure the path is co

MySQL 05 stored procedure

How to realize the full-text content retrieval of word, PDF and txt files?

建木持续集成平台v2.5.2发布

Typescript installation
随机推荐
nacos显示服务注册地址错误
JDBC-MySql 02 数据访问和DAO模式
百度地图技术概述,及基本API与WebApi的应用开发
电动加热护颈枕芯片-DLTAP703SC
Collection of software design suggestions of "high cohesion and low coupling"
JS to realize simple form verification and select all functions
订单超时取消 及 按类别查询商品
RuntimeError: output with shape [1, 256, 256] doesn‘t match the broadcast shape [3, 256, 256]【报错】
MongoDB
MySQL 02 初体验
Redis注解
Uniapp H5 cross domain problem
LED学习护眼台灯触摸芯片-DLT8T10S-杰力科创
MySQL 03 高级查询(一)
MySQL 05 stored procedure
INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
TS study notes class
文件的上传和下载
Bathroom with demister vanity mirror touch chip-dlt8t10s
Alibaba architects spent 280 hours sorting out 1015 pages of distributed full stack pamphlets to easily start the distributed system