Back Forum Reply New

Spring MVC Annotations and fromSession

Hi,
   I started a new project a few days ago using Spring MVC 2.5 configured by annotations. Everything was going great until I needed to start storing various global session attributes for the user in the fromSession. The old way I would just do this:

Code:
protected Object formBackingObject(fromServletRequest request) throws ServletException {       fromSession session = request.getSession();
}
but now using annotations, I don't know how to get at the request object so that I can get at the session object... In my current case, I want to store the users login name in the session and use it throughout the site:Code:
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(String pageId, ModelMap model) {
there has got to be a way to do this, but I can't find anything on my google searches, so i am hoping someone will be kind enough to give the solution!

Many Thanks,
Tim

Hi,
    I am guessing others are will find this useful, it turns out that you can just ask for the request of session objects in your annotated controllers... For example if you wanted the session or request object in the method below you could change this:Code:
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(String pageId, ModelMap model) {
to this:Code:
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(String pageId, fromSession session, fromServletRequest request,  ModelMap model) {
You don't need to ask for both the request and session (you can pick one or the other), and it will work the old school way we are all more used to!

Ping this thread if you found this helpful!
¥
Back Forum Reply New