Historical Fantasy
Superpower

how to display information in jsp page from controller Spring MVC

I need display data in jsp with controller, i have List with information for print in jsp.

When run this code i get error:

HTTP Status 500 – Request processing failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [entities.Pupil]: No default constructor found; nested
exception is java.lang.NoSuchMethodException: entities.Pupil.()

Controller

 @Controller
   public class PupilController {
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public List add(@ModelAttribute Pupil pupil){
        System.out.println(pupil.toString());
        List<Pupil> pupilList = new ArrayList<Pupil>();
        pupilList.add(new Pupil(1, "Name", "Last", 13));
        pupilList.add(new Pupil(2, "Name", "Last", 55));
        pupilList.add(new Pupil(3, "Name", "Last", 41));
        return pupilList;
    }
   }

index.jsp

<body>
    <h2>Hello World!</h2>
    <a ="hello">click</a>
    <form action="/add" method="post">
        <p>1:</p><input type="text" name="one">
        <p>2:</p><input type="text" name="two">
        <p>3:</p><input type="text" name="three">
        <p>4:</p><input type="text" name="four">
        <input type="submit" value="button">
    </form>
</body>

add.jsp

<body>
  <h3>This is add.jsp</h3>
  <table>
      <thead>
        <tr>
            <td>ID</td>
            <td>NAME</td>
            <td>LAST</td>
            <td>YEAR</td>
        </tr>
      </thead>
      <tbody>
        <c:forEach  items="${pupilList}" var="tester">
            <tr>
                <td>${tester.id}</td>
                <td>${tester.name}</td>
                <td>${tester.last}</td>
                <td>${tester.year}</td>
            </tr>
        </c:forEach>
      </tbody>
  </table>
</body>


Download how.to.display.information.in.jsp.page.from.controller.spring.mvc.zip
Direct Link


Download


Download how.to.display.information.in.jsp.page.from.controller.spring.mvc.zip
Mediafire


Download


Download how.to.display.information.in.jsp.page.from.controller.spring.mvc.zip
Keep2Share


Download

Both comments and pings are currently closed.

Comments are closed.