当前位置:网站首页>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
边栏推荐
- The understanding of string in C.
- Extension of regular expression
- Code interview of Amazon
- Double insurance for line breaking
- Some advice for NS2 beginner.
- 正则表达式的扩展
- Hash、Set、List、Zset、BitMap、Scan
- 2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题
- Useful resources for ns2
- Unity learning notes (rigid body physics collider trigger)
猜你喜欢
随机推荐
Unity display Kinect depth data
ES6学习笔记(1)——快速入门
阿里云视频点播服务的开通和使用
Useful resources for ns2
功率单位(power control)
转行软测&跳槽到新公司,工作怎样快速上手?
Express get/post/delete... Request
Questions about webservice
Leetcode brushes questions the next day
Kinect2 for unity3d - avatardemo learning
Nacos基本概念和单机部署
The great idea of NS2
Latex使用-控制表格或者图形的显示位置
Collection of software design suggestions of "high cohesion and low coupling"
Using MATLAB to generate graphics for journals and conferences - plot
C file and folder input / output stream code
C interface knowledge collection suggestions collection
Jmeter接口自动化-如何解决请求头Content-Type冲突问题
Electric heating neck pillow chip-dltap703sc
Household mute mosquito repellent lamp chip-dltap703sd-jericho








