Creating the course list view

We now have all the classes to get courses. Let's now create a JSP to display the list of courses. Create courses.jsp in the src/main/webapp/WEB-INF/views folder. Add the following content in the HTML body tag of the page:

<h2>Courses:</h2> 
 
<table> 
  <tr> 
    <th>Id</th> 
    <th>Name</th> 
    <th>Credits</th> 
    <th></th> 
  </tr> 
  <c:forEach items="${courses}" var="course"> 
    <tr> 
      <td>${course.id}</td> 
      <td>${course.name}</td> 
      <td>${course.credits}</td> 
    </tr> 
  </c:forEach> 
</table> 

The View page makes use of JSTL tags to iterate over courses (using the variable that was made available in the Model by the Controller) and displays them.

We are not going to build the entire application here. The idea was to understand how to use JPA with Spring MVC, which we have learned in this section. Browse to http://localhost:8080/course_management_jpa/courses to run the application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.226