How to pass an object from the controller to the view in SpringMVC?

Posted by {"name"=>"Palash Ray", "email"=>"paawak@gmail.com", "url"=>"https://www.linkedin.com/in/palash-ray/"} on July 13, 2008 · 1 min read

The scenario is: I want to show a list of items on my view from the database. My controller picks up the data, passes it to the view which displays it. I am using a sub class of org.springframework.web.servlet.mvc.SimpleFormController:
@Override
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView view = new ModelAndView("complaintListings");
List strings = new ArrayList();
strings.add("AAAAAAAA");
strings.add("BBBBBBB");
strings.add("CCCCCCCC");
strings.add("EEEEEEEE");
strings.add("FFFFFFFFF");
//set the object to view
view.addObject("testStrings", strings);
return view;
}
The view looks like this:




Its that simple!