I'm doing a little project with Spring 3 MVC & jQuery
I'm not sure how to ask it so i'll try to explain
I have this scenario :
LoginPage(with User object model) ---submit--> Server sends OK back to LoginPage --> (LoginPage) redirect to Page2 using window.location = "Page2"
Problem : Page 2 doesn't recognize User
How to make it work? I tried reading about @SessionAttributes
but didn't really understand it.
@Controller
public class LoginController {
...
...
@RequestMapping(value = "/")
public ModelAndView loginPage(ModelMap model) {
model.addAttribute("user", new User());
logger.info("Loading Login Page");
return new ModelAndView("login");
}
@RequestMapping(value = "/loginSubmit.html" ,method=RequestMethod.GET)
public String processSubmit( ModelMap model, User user) throws InterruptedException{
...
...
return "1" to login page
...
...
Here I want User user to be known from last controller,but it's making a new one instead.
@Controller
public class Controller2 {
@RequestMapping(value = "/home")
public String home(ModelMap model, User user) {
...
...
}
LoginPage.jsp
$.get("loginSubmit.html", form1Var.serialize(), function(data){
var isSucess = data.charAt(0) == "1" ? true : false;
if ( isSucess == true) {
alert("ok...");
window.location = "home";
}
EDIT Moved my solution to Answers.