The Filter Filter
It is one of the three main components of JavaWeb. Three components are: Servlet program, Listener, Filter Filter. Filter Filter is the JavaEE specification. It’s also the interface. The Filter Filter is used to intercept requests and Filter responses. Common application scenarios for intercepting requests are:
Permission checking diary operation transaction management requirements: Under your web project, there is an admin directory. All resources in the admin directory (HTML pages, JPG images, JSP files, and so on) must be logged in by the user before they can be accessed.
import com.wz.userManager.pojo.User;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebFilter(filterName = "UserCenterFilter",urlPatterns = {"/pages/*"})
public class UserCenterFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)servletRequest;
HttpServletResponse resp= (HttpServletResponse)servletResponse;
HttpSession session = req.getSession();
User username = (User) session.getAttribute("user");
if(username==null){
servletRequest.getRequestDispatcher("/login.jsp").forward(servletRequest,servletResponse);
}else{
filterChain.doFilter(servletRequest,servletResponse);
}
}
@Override
public void destroy() {
}
}
Read More:
- Introduction of Hadoop HDFS and the use of basic client commands
- [Solved] Logon failed, use ctrl+c to cancel basic credential prompt. unable to access
- VC + + OpenGL is used as the development platform to design the program, which can generate any pixel on the screen, and use the pixel to draw the basic graphics
- The built-in filter function in Excel can’t contain all the items
- Failed to resolve filter: ToFixed
- Regular expressions filter special characters
- HTTP Basic: Access denied
- VTK basic learning
- Git report HTTP Basic: Access denied
- VBoxClient (seamless): failed to start. Stage: Setting guest IRQ filter mas Error: VERR_INTERNAL_ERR
- Register global time filter in main.js in Vue
- Simple understanding and basic operation of mongodb
- Basic formula of logarithm operation
- git remote: HTTP Basic: Access denied error resolution
- Error c2371: ‘xxx’: redefinition; different basic types solutions
- Error in Git operation: http basic: access denied solution
- Common problems and basic concept knowledge of OpenGL
- CentOS Basic XLib functionality test failed!
- Configure glut in Ubuntu and implement basic OpenGL experiment on CodeBlocks platform
- error Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager“