Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Controller:

@Controller
@RequestMapping("/articles")
@SessionAttributes({"user_sess"})
public class ArticleController {
@Autowired
private ArticleService articleService;

@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView saveArticle(@ModelAttribute(" article ") Article article,
BindingResult result) {
ModelAndView modelAndView = new ModelAndView();

modelAndView.addObject("user_sess",article.getUser ());
System.out.println("article.getUser()"+article.get User());
articleService.addArticle( article);

// session.setAttribute("user_Sess", article.getUser());
// return new ModelAndView("redirect:/articles.html");
return new ModelAndView("Welcome");
}

@RequestMapping(method = RequestMethod.GET)
public ModelAndView listArticles() {
Map<string,> model = new HashMap<string,>();
model.put("articles", articleService.listArticles());

return new ModelAndView("articlesList", model);
}

@RequestMapping(value = "/add", method = RequestMethod.GET)
public ModelAndView addArticle(@ModelAttribute("article") Article article,
BindingResult result) {
return new ModelAndView("addArticle");
}
}

In Jsp page Welcome.jsp :

Welcome: ${user_sess}


//Dont know how to use session variable because value is not received in jsp page.It is a simple spring mvc 3 hibernate project using database mysql. Please help me
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900