I have a login page where the user can log into myb application. When the user click on the button "log in", the request is processed by the following controller :
@Controller
@SessionAttributes("user-entity")
public class LoginController extends BaseController {
@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView login(WebRequest webRequest, @ModelAttribute("user") User user) {
return new ModelAndView(VIEW_LOGIN_NAME, "user-entity", user);
}
In the above code, I have added the user-entity ( user ) in the session. But I am not able to retrieve the user-entity in another controller :
@Controller
public class ProfileController extends BaseController{
@RequestMapping(value="/saveprofil", method = RequestMethod.POST)
public ModelAndView saveProfile(@ModelAttribute Profil profil,HttpSession session){
User user = (User) session.getAttribute("user-entity");
user.setProfil(profil);
userServices.createUser(user);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("saveProfilSuccess");
return modelAndView;
}
The user object is not null but all attributes are null. What's wrong?