2012-08-08 2 views
0

현재 저는 기존의 Spring 2.5 응용 프로그램을 사용하고 있으며 사용자 정의 컨트롤러 (SimpleFormController 확장) 유효성 검사 로직을 수정하고 싶습니다.스프링 MVC - onBindAndValidate 안에 쿠키 추가

protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception; 

내가이 방법으로 제공하고자하는 것은 내가 제공받은 서비스 클래스의 결과에 따라 쿠키를 쓰는 것입니다.

  • 하나가 쿠키를 작성하는 HttpServletResponse 개체를 검색 : 나는 HttpServletResponse 개체에 액세스 할 수없는 컨트롤러의 워크 플로우 내부의이 시점에서 때문에, 다른 방식이있다. 또는.
  • 쿠키를 생성하기 위해 Spring MVC 내의 다른 기능을 사용하십시오. 나는 org.springframework.web.util.CookieGenerator을 보았지만 여전히 응답 객체가 필요합니다.

누구나 제공 할 수있는 도움에 감사드립니다.

감사합니다.

답변

0

글쎄, 스프링 MVC 2.5에서이 작업을 수행 할 수있는 직관적 인 내장 메소드를 찾을 수 없다는 사실이 밝혀졌습니다.

내가 끝낸 것은이 해킹입니다. 우선은 서블릿 호환 getCookie() 방법을 노출 (이 호출 할 수 있습니다 곳) 결과 서비스 개체를 걸릴 것 유틸리티 함수 클래스를 호출하는 내 컨트롤러를 수정하고 배치하는 사용자의 세션에서 이렇게 같은 :

WebUtils.setSessionAttribute(request, "myResponseObjectSessionName", myResponseObject); 
그들은 모두 SimpleFormController에서 상속 이후

지금, 내가 대신 여전히 전에서 상속 새로운 추상 클래스를 생성하지만, 지금처럼 handleRequestInternal() 방법을 수정 한 : 매우 우아하지

public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 

    // let the controller do it's job 
    ModelAndView result = handleRequestInternal(request, response, errors); 

    // and then use a helper class to inspect the session, find the session attribute 
    // 'myResponseObjectSessionName', and set any cookies left in case it does exist at 
    // this point in time. 
    new ProcessServiceObject().setServiceResponseCookie(request, response); 

    return result; 
} 

을하지만 난 그것을 작동 생각합니다. 건배.