Spring MVC: HTTP session management “equivalent”

前端 未结 1 698
旧巷少年郎
旧巷少年郎 2021-01-22 14:48

I come from languages like PHP or ColdFusion: if I wanted to save something in user\'s http session I act like this:

SESSION[\"foo\"] = \"bar\"

1条回答
  •  情话喂你
    2021-01-22 15:26

    You may use a session-scoped bean, and you may also have an argument of type HttpServletRequest or HttpSession on all your request handling methods. See 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);
        ...
    }
    

    0 讨论(0)
提交回复
热议问题