javajspspring-mvcpropertynotfoundexception

javax.el.PropertyNotFoundException:


I am working on Spring. I am unable to display the list items in JSP. It says: Property not found on type java.lang.String. I have a POJO class Student:

public class Student {
    private Integer age;
    private String name;
    private Integer id;

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }      
}

In my controller class I fetch list of students and assign it to a List and add the list to the model attribute. Which is as follows.

@RequestMapping("/getstuds")
public String getstudents(@ModelAttribute Student student, ModelMap model){
    StudentDAO studentDAO = (StudentJDBCTemplate)applicationContext.getBean("studentJDBCTemplate");
    List<Student> students = studentDAO.listStudents();
    model.addAttribute("studlist",students);
    System.out.println(students.iterator().next().getName());
    return "showstuds";     
}

showstuds.jsp

<table>
    <c:forEach var="stud" items="${studlist} }">
        <tr><td>${stud.Name}</td></tr>
    </c:forEach>
</table>

I get the following exception:

javax.el.PropertyNotFoundException: Property 'Name' not found on type com.spring.mvc.Student


Solution

  • your variable name is name not Name

    <tr><td>${stud.name}</td></tr>
    

    instead of

    <tr><td>${stud.Name}</td></tr>
    

    And also remove the brace

    items="${studlist}" 
    

    instead of

    items="${studlist} }"