how to display model attribute in jsp using Spring MVC? how to display model attribute in jsp using Spring MVC? spring spring

how to display model attribute in jsp using Spring MVC?


Sample Code

class UserForm {    private String name;    private String address;    //setter and getter}

In Your Controller

 @RequestMapper(value="/user")    public ModelAndView user(){        ModelAndView mav = new ModelAndView("userForm") ;        List<UserForm> userForms = yourDatabaseCall();        mav.addObject("userForms", userForms);          return mav;``    }

in jsp page:

<c:forEach items="${userForms}" var="userForm">        <c:out value="${userForm.name}"/>   <c:out value="${userForm.address}"/></c:forEach>


You can add list of userFomrs as a model attribute

List<UserForm> userForms = yourDatabaseCall();model.addAttribute("userForms", userForms);     

In JSTL you can iterate over it

<c:forEach items="${userForms}" var="userForm">        // Do something</c:forEach>