복붙노트

[SPRING] Spring MVC : HTTP 세션 관리 "equivalent"

SPRING

Spring MVC : HTTP 세션 관리 "equivalent"

PHP 나 ColdFusion과 같은 언어에서 왔습니다 : 사용자의 http 세션에서 뭔가를 저장하고 싶다면 다음과 같이 행동하십시오.

SESSION["foo"] = "bar"

이제 나는 Spring MVC 환경에있다.

예를 들어 컨트롤러 메서드 내에서 변수를 세션에 저장하려면 어떻게해야합니까?

누군가 세션 스코프 된 bean이 그 일을 할 것이라고 말했다.

사소한 코드 스 니펫으로 나를 도울 수 있습니까?

해결법

  1. ==============================

    1.세션 범위 bean을 사용할 수 있으며 모든 요청 처리 메소드에 HttpServletRequest 또는 HttpSession 유형의 인수가있을 수도 있습니다. http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-methods를 참조하십시오.

    세션 범위 bean을 사용할 수 있으며 모든 요청 처리 메소드에 HttpServletRequest 또는 HttpSession 유형의 인수가있을 수도 있습니다. http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-methods를 참조하십시오.

    @RequestMapping...)
    public String processSubmit(..., HttpSession session, ...) {
        ...
        session.setAttribute("someAttribute", someObject);
        ...
    }
    
  2. from https://stackoverflow.com/questions/8680529/spring-mvc-http-session-management-equivalent by cc-by-sa and MIT license