• 对某个页面的过滤


    package work;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    public class LoginFilter implements Filter {
        public void destroy() {}
        public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain filterchain) throws IOException, ServletException {
            HttpServletRequest requ=(HttpServletRequest)request;
            HttpServletResponse resp=(HttpServletResponse)response;
            HttpSession session=requ.getSession(true);
    
            if(session.getAttribute("name")==null){
                resp.sendRedirect("Login.jsp");
            }else{
                filterchain.doFilter(request, response);
            }
        }
        public void init(FilterConfig arg0) throws ServletException {}
    
    }

    web.xml

    <filter>
          <filter-name>LoginFilter</filter-name>
          <filter-class>work.LoginFilter</filter-class>
      </filter>
    <filter-mapping>
          <filter-name>LoginFilter</filter-name>
          <url-pattern>/Cloud.jsp</url-pattern>
      </filter-mapping>
  • 相关阅读:
    MongoDB学习笔记(查询)
    PHP IP地址转换
    PHP SESSION的工作原理解析(转)
    JavaScript 之 RegExp 对象
    jquery 几个实用的小方法
    JS之document.cookie随笔
    CodeForces
    CodeForces
    翻转 -- CodeForces
    Codeforces --- 982C Cut 'em all! DFS加贪心
  • 原文地址:https://www.cnblogs.com/lls1350767625/p/7989888.html
Copyright © 2020-2023  润新知