I have a pretty simple webapp that follows the tutorials set out by Mkyong and others.
I want my webapp's scope be distingushed by the browser session. That is a different user, or different browser tab should not share objects with the other users/browser tabs.
Here we make minimal changes to the code set out in the tutorial:
package com.mkyong.common.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/welcome")
public class HelloController {
private int i = 0;
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model, HttpServletRequest r) {
System.out.println(r.getSession().getId());
System.out.println(i++);
model.addAttribute("message", "Spring 3 MVC Hello World");
return "hello";
}
}
Output:
F6E793D5ED12880E2F909A1A0C1D2D98
0
3E53022170EB77C0208AC0221A68D4D8
1
38A432F7C813A775E8F201AFB42178DB
2
What this shows is that there are different Http sessions, but they have the same shared resources.
How do I distinguish them?