예를들어, main페이지로 접근한 사용자가
로그인되어있는 상태라면 => main페이지로 redirect
로그인 되어있지 않은 상태라면 => 로그인 페이지로 redirect
로그인 되어있는 상태를 확인하기위해 main으로 들어오는 요청(url)을 필터처리 한다고 하자.
로그인 되어있지 않은상태라면 로그인페이지로 정상적으로 이동하지만,
로그인 되어있는 상태라면 main으로 redirect하게되는데, 이때 문제가 fillter를 계속 해서 탄다는것이다.(main을 redirect하므로)
https://stackoverflow.com/questions/42219650/too-many-redirects-using-filter-class
스택오버플로우에서 해답을 찾았다.
바로 filter mapping의 dispatcher옵션을 사용하는것.
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/kogile/startPage</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
그리고
main으로 다시 요청을 날릴경우, getRequestDispatcher("url").forward() 메서드를 사용하면,
filter를 타지 않는다.
if(isUserThere == false){
((HttpServletResponse) response).sendRedirect("/kogile/login");
}else{
((HttpServletRequest)request).getRequestDispatcher("/kogile/startPage").forward(request, response);
}
'Today I learned' 카테고리의 다른 글
Spring with Oracle 쿼리 연동 (0) | 2019.03.19 |
---|---|
Spring, RestController에서 @PathVariable로 email을 넘길때 이슈. (1) | 2019.02.21 |
[Mybatis] Invalid bound statement (not found) 에러 (0) | 2019.02.15 |
javascript Rest 처리 & Ajax 코드 (0) | 2019.02.01 |
1월29일 (0) | 2019.01.29 |
댓글