관리 메뉴

nalaolla

인터셉터(Interceptor) 사용하기 본문

SPRING

인터셉터(Interceptor) 사용하기

날아올라↗↗ 2016. 3. 18. 09:49
728x90
반응형

인터셉터(Interceptor) 사용하기



==================================

servlet-context.xml

==================================

<interceptors>

<interceptor>

<mapping path="/**" />

<beans:bean class="test.com.spring19interceptor.TestInterceptor"></beans:bean>

</interceptor>

</interceptors>




==================================

TestInterceptor.java

==================================


import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class TestInterceptor extends HandlerInterceptorAdapter {

private static final Logger logger = LoggerFactory

.getLogger(TestInterceptor.class);


// private static final String[] SPATH_LIST = { "/", "/home.do", "/login.do" };


@Override

public boolean preHandle(HttpServletRequest request,

HttpServletResponse response, Object handler) throws Exception {


String sPath = request.getServletPath();

logger.info("sPath : "+sPath);

return true;

}

}







==================================

Session 분기

==================================

HttpSession session = request.getSession();

String session_id = 

(String) session.getAttribute("LOGIN_ID");

if(sPath.compareTo("/select.do")==0){

logger.info("session_id : "+session_id);

if(session_id==null){

response.sendRedirect("login.do");

return false;

}

}



728x90
반응형

'SPRING' 카테고리의 다른 글

SqlSession + MyBatis + 프로시져 호출하여 우편번호 가져오기  (0) 2016.03.26
AOP-Aspect Oriented Programming  (0) 2016.03.25
log4j 사용 및 적용방법  (0) 2016.03.17
mybatis사용하기  (0) 2016.03.16
BasicDataSource 적용하기  (0) 2016.03.14