// servlet-context
<!-- 인터셉터 설정
-LoginInterceptor 클래스를 빈으로 정의한다.
** 생성한 클래스는 해당 위치에 존재해야합니다. (패키지 구조에 맞는 형태로 ::: 없으면 에러남)
-->
<beans:bean id="loginInterceptor"
class="kr.or.ddit.controller.intercept.loginInterceptor"></beans:bean>
<interceptors>
<interceptor>
<mapping path="/intercept/login"/>
<beans:ref bean="loginInterceptor"/>
</interceptor>
</interceptors>
// LoginController
package kr.or.ddit.controller.intercept;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import kr.or.ddit.vo.crud.CrudMember;
@Controller
@RequestMapping("/intercept")
public class LoginController {
@RequestMapping(value="/login", method = RequestMethod.GET)
public String loginForm() {
return "login/loginForm";
}
@RequestMapping(value="/login",method=RequestMethod.POST)
public String login(String userId, String userPw, Model model) {
CrudMember member = new CrudMember();
member.setUserId(userId);
member.setUserPw(userPw);
member.setUserName("홍길동");
model.addAttribute("user", member);
return "login/success";
}
}
//LoginInerceptor
public class LoginInterceptor extends HandlerInterceptorAdapter{
private static final String USER_INFO = "userInfo";
// 쓰고 alt +Shift + s -> 오버라이드 / 인플리먼트 메소드누르면
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
// TODO Auto-generated method stub
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// TODO Auto-generated method stub
super.postHandle(request, response, handler, modelAndView);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// TODO Auto-generated method stub
super.afterCompletion(request, response, handler, ex);
}
//이렇게 세개의 메소드 생김