في هذا الموضوع سأشرح بشكل مبسط التعامل مع SESSION في Spring MVC
الصورة من المشروع الذي أعمل عليه شخصيا وهي للتوضيح فقط
1. في Controller الخاص بك, تقوم باضافة HttpServletRequest request الى البارامترز
مثال :
public ModelAndView f3(@ModelAttribute("emp") Employee emp, HttpServletRequest request)
ثم في داخل ال Methode نستعمل
request.getSession().setAttribute("varname", "value");
مثال كامل
@RequestMapping(value = "/logingo.html", method = RequestMethod.POST)
public ModelAndView f3(@ModelAttribute("emp") Employee emp, HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView("OkForm");
request.getSession().setAttribute("user", emp.getEmail());
}
return modelAndView;
}
لاستعمالها في JSP
${sessionScope.user}
لا توجد تعليقات لهذا الموضوع