Am using spring mvc i want to access an request attribute inside @ModelAttribute
method but its giving only null
@RequestMapping(value = "/abc", method = RequestMethod.GET, params = "data")
public ModelAndView aaaa()
{
String courseId = httpServletRequest.getParameter("courseValue");
System.out.println("course value data :" + courseId); // here am getting value
httpServletRequest.setAttribute("courseId", courseId); // setting in request
attribute
WebUtils.setSessionAttribute(httpServletRequest, "courseId", courseId);
// setting in session attribute
ModelAndView modelAndView = new ModelAndView("abc");
return modelAndView;
}
@ModelAttribute("termList")
public Map<String, String> def(HttpServletRequest httpServletRequest)
{
String courseId = (String) WebUtils
.getSessionAttribute(httpServletRequest, "courseId");
System.out.println("course value in term :" + courseId); // here its giving null
Map<String, String>map = courseSubLinkService.getTermDetailsBasedOnCourseId
(courseId);
httpServletRequest.setAttribute("termList", map);
return map;
}
I dont know where i did wrong please help me to get this value
From Spring docs:
This means that in moment when
def
is invoked HttpServletRequest hasn't attribute that you need because you set this attribute inaaaa
method that will be invoked afterdef
.