当前位置:网站首页>SSM project uses filter to realize login monitoring
SSM project uses filter to realize login monitoring
2022-07-27 19:08:00 【qq_ forty-two million forty-two thousand one hundred and fifty-】
SSM Configure filters in the project to realize login monitoring , Some pages cannot be accessed without login
- Write a class implementation of the filter Filter Interface , Add specific operations to the implementation method
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 {
// initialization :web The server will initialize when it starts
@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 {
// Let the request go on , If you don't write , Requests will be blocked here
filterChain.doFilter(servletRequest,servletResponse);
}
}
// The destruction ,web It will be destroyed when the server is shut down
@Override
public void destroy() {
}
- stay web.xml Filter in
<filter>
<filter-name>LoginFilter</filter-name>
<!-- Realization filter The class of the interface -->
<filter-class>edu.gnnu.newcomer.aop.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<!-- Pages to filter -->
<url-pattern>/manager/*</url-pattern>
</filter-mapping>
After configuration, these pages will be filtered first , If the conditions in the filter are not met, perform the operations defined in the filter
边栏推荐
猜你喜欢

专项测试之「 性能测试」总结

Selenium自动化测试面试题全家桶

Electric heating neck pillow chip-dltap703sc

Full automatic breast pump chip dltap703sd

I'm afraid I won't use the JMeter interface testing tool if I accept this practical case

Unity learning notes (realize the conveyor belt)

Nodejs template engine EJS

「测试新手百科」5 分钟快速上手Pytest 自动化测试框架

Kinect for unity3d - backgroundremovaldemo learning

连续时间系统的性能分析(2)-二阶系统性能改善方式PID,PR
随机推荐
NPM basic use
Latex use - subfigure vertical graphics
The great idea of NS2
Kinect for Unity3d----KinectManager
Mini washing machine touch chip dlt8ma12ts Jericho
阿里云对象存储OSS的开通和使用
Code interview of Amazon
Acquisition data transmission mode and online monitoring system of vibrating wire wireless acquisition instrument for engineering instruments
Express get/post/delete... Request
Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
Resource for NS2 beginner
Jmeter接口自动化-如何解决请求头Content-Type冲突问题
Latex使用--subfigure竖排图形
Kinect for Unity3d----KinectManager
收下这份实操案例,还怕不会用Jmeter接口测试工具
Kinect2 for Unity3D——AvatarDemo学习
Hash、Set、List、Zset、BitMap、Scan
ES6数值的扩展
阿里云视频点播服务的开通和使用
C interface knowledge collection suggestions collection