servlet-context.xml 설정 추가
<interceptors>
<interceptor>
<mapping path="/**/*" />
<exclude-mapping path="/main/*"/>
<exclude-mapping path="/login/*"/>
<beans:bean class="com.d4emon.interceptor.SessionInterceptor"></beans:bean>
</interceptor>
</interceptors>
*** exclude-maping 은 Spring 3.2 부터 지원한다. ****
SessionInterceptor.java 파일 생성
package com.d4emon.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class SessionInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("Interceptor : PreHandle");
// Session userid check
HttpSession session = request.getSession();
String userid = (String) session.getAttribute("userid");
// Login false
if(null==userid) {
System.out.println("Interceptor : Session Check Fail");
// main page 로 이동
response.sendRedirect("/main/main.do");
return false;
}
// Login true
else {
System.out.println("Interceptor : Session Check true");
return super.preHandle(request, response, handler);
}
}
}
'Framework' 카테고리의 다른 글
[Spring, Mybatis] Error setting null for parameter #3 with JdbcType OTHER (0) | 2015.02.17 |
---|---|
[Spring] Error creating bean with name 'sampleBean': Injection of resource dependencies failed; (0) | 2015.01.27 |
[Spring] spring 3.1 을 3.2 로 올리는 방법 (maven) (0) | 2014.12.10 |
[Spring] nested exception is java.lang.NullPointerException (0) | 2014.12.09 |
[Mybatis] org.apache.ibatis.type.TypeException (0) | 2014.11.17 |