AuthFilter1.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;

public class AuthFilter1 implements Filter{

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain){

        try{

            String target = ((HttpServletRequest)request).getRequestURI();

            HttpSession session = ((HttpServletRequest)request).getSession();

            if (session == null){
                session = ((HttpServletRequest)request).getSession(true);

                ((HttpServletResponse)response).sendRedirect("/schedule/LoginPage");
            }else{
                Object loginCheck = session.getAttribute("login");
                if (loginCheck == null){
                    ((HttpServletResponse)response).sendRedirect("/schedule/LoginPage");
                }
            }

            chain.doFilter(request, response);

        }catch (ServletException se){
        }catch (IOException e){
        }

    }

    public void init(FilterConfig filterConfig) throws ServletException{
    }

    public void destroy(){
    }
}

( Written by Tatsuo Ikura )

Profile
profile_img

著者 / TATSUO IKURA

初心者~中級者の方を対象としたプログラミング方法や開発環境の構築の解説を行うサイトの運営を行っています。