I have a problem with HttpSession, I do not have it
I think I forget an Annotation or anything like this.
Do I need anywhere to do a session.create() ?
In UserController :
@Controller
public UserController{
public ResponseHttp connection(User userSent, HttpSession session) {
ResponseHttp responseHttp = new ResponseHttp();
//function to check login/mdp
if (check) {
responseHttp.setSuccess(true);
responseHttp.setMessage("Connection success");
//some code
//
//
session.setAttribute("userId", 1); // this is an example
System.out.println(session.getAttribute("userId")) // return 1
return responseHttp;
}
}
responseHttp.setSuccess(false);
responseHttp.setMessage("Connection failed");
return responseHttp;
}
}
In another controller :
@Controller
public class MyController{
public void test(HttpSession session){
System.out.println(session.getAttribute("userId")) ; // return null
}
}
UPDATE 25-06-2017
I tried to inject @HttpSession in both controllers At connection I check the session like that :
if(httpSession.isNew()){
System.out.println("New") // ok return new !
System.out.println(httpSession.getId()); // A87AC018FD8DDA33B023FAA6C1C2D71C
}
In the other controller
if(httpSession.isNew()){
System.out.println("New") // it's returning new again
System.out.println(httpSession.getId()); // 2FE08FB68EA53F7FEBB8143CFEE6A9EB
}else{
System.our.println("not new")
}
Question: Why is not the same session ?