title: Not able to display List of objects in JSP page based on the given input using Spring MVC JPA using Spring Boot
body: <p>I am trying to display List of Student objects based on their Course on JSP page using Spring MVC and JPA using Spring Boot</p>
  <p>I am using the JSP page <code>searchByCourse.jsp</code> page as shown below and on the JSP page, the list of student objects based on the given course is not displayed.
  And also the methods in the repository file <code>StudentRepo.java</code> are not showing any output as well. I have marked them in the comments in the <code>StudentController.java</code>.</p>
  <p>I am not able to understand where I made the mistake.
  Your help would be really appreciated.</p>
  <p>Below are the files I am using.</p>
  <p><strong>Student.java</strong></p>
  <pre><code>package com.springcourse.springmvcboot.model;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class Student 
  {
      @Id
      private int studID;
      private String studName;
      private String studCourse;
  
      public String getStudCourse() {
          return studCourse;
      }
  
      public void setStudCourse(String studCourse) {
          this.studCourse = studCourse;
      }
  
      public int getStudID() {
          return studID;
      }
      
      public void setStudID(int studID) {
          this.studID = studID;
      }
      
      public String getStudName() {
          return studName;
      }
      
      public void setStudName(String studName) {
          this.studName = studName;
      }
  
      @Override
      public String toString() {
          return &quot;Student [studID=&quot; + studID + &quot;, studName=&quot; + studName + &quot;, studCourse=&quot; + studCourse + &quot;]&quot;;
      }
          
  }
  </code></pre>
  <p><strong>StudentController.java</strong></p>
  <pre><code>package com.springcourse.springmvcboot;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.springcourse.springmvcboot.dao.StudentRepo;
  import com.springcourse.springmvcboot.model.Student;
  
  @Controller
  public class StudentController 
  {
      @Autowired
      StudentRepo studrepo;
      
      @RequestMapping(&quot;/&quot;)
      public String home()
      {
          return &quot;home.jsp&quot;;
      } 
      
      @RequestMapping(&quot;/addStudent&quot;)
      public String addStudent(Student stud)
      {
          studrepo.save(stud);
          return &quot;home.jsp&quot;;
      }
      
      @RequestMapping(&quot;/getStudent&quot;)
      public ModelAndView getStudent(@RequestParam int studID)
      {
          ModelAndView mv = new ModelAndView(&quot;showStudent.jsp&quot;);
          Student student = studrepo.findById(studID).orElse(new Student());
          mv.addObject(student);
          
          return mv;
      }
      
      @RequestMapping(&quot;/deleteStudent&quot;)
      public ModelAndView deleteStudent(@RequestParam int studID)
      {
          ModelAndView mv = new ModelAndView(&quot;deleteStudent.jsp&quot;);
          Student student = studrepo.findById(studID).orElse(new Student());
          studrepo.deleteById(studID);
          mv.addObject(student);
          
          return mv;
      }
      
      @RequestMapping(&quot;/deleteAllStudent&quot;)
      public ModelAndView deleteAllStudent()
      {
          ModelAndView mv = new ModelAndView(&quot;deleteAllStudent.jsp&quot;);
          studrepo.deleteAll();
          
          return mv;
      }
      
      @RequestMapping(&quot;/searchByCourse&quot;)
      public ModelAndView searchByCourse(@RequestParam String studCourse)
      {
          ModelAndView mv = new ModelAndView(&quot;searchByCourse.jsp&quot;);
          List&lt;Student&gt; studList = studrepo.findByStudCourse(studCourse);
          
          mv.addObject(&quot;stlist&quot;, studList);
          
          System.out.println(studrepo.findByStudCourse(&quot;Java&quot;));//Not displaying any output
          System.out.println(studrepo.findByStudIDLessThan(105));
          System.out.println(studrepo.findByStudCourseSorted(&quot;Java&quot;));//Not displaying any output
          
          return mv;
      }
  }
  </code></pre>
  <p><strong>StudentRepo.java</strong></p>
  <pre><code>package com.springcourse.springmvcboot.dao;
  
  import java.util.List;
  
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.repository.CrudRepository;
  
  import com.springcourse.springmvcboot.model.Student;
  
  public interface StudentRepo extends CrudRepository&lt;Student, Integer&gt;
  {
      List&lt;Student&gt; findByStudCourse(String studCourse);
      
      List&lt;Student&gt; findByStudIDLessThan(int studID);
      
      
      @Query(&quot;from Student where studCourse=?1 order by studName&quot;)
      List&lt;Student&gt; findByStudCourseSorted(String studCourse);
  }
  </code></pre>
  <p>The JSP file used to display</p>
  <p><strong>searchByCourse.jsp</strong></p>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;%@taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot;%&gt;
  &lt;%@taglib prefix=&quot;form&quot; uri=&quot;http://www.springframework.org/tags/form&quot;%&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;ISO-8859-1&quot;&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  The List of Students are &lt;br&gt;
  
  &lt;c:forEach items=&quot;${stlist}&quot; var=&quot;st&quot;&gt;
          &lt;li&gt;${st}&lt;/li&gt;
  &lt;/c:forEach&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>And finally the pom.xml file</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.3.5.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.springcourse&lt;/groupId&gt;
      &lt;artifactId&gt;springmvcjpaboot&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;springmvcjpaboot&lt;/name&gt;
      &lt;description&gt;Demo project for Spring MVC with Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
      &lt;artifactId&gt;tomcat-jasper&lt;/artifactId&gt;
      &lt;version&gt;9.0.39&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;!-- https://mvnrepository.com/artifact/jstl/jstl --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;jstl&lt;/groupId&gt;
      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;!-- https://mvnrepository.com/artifact/javax.servlet/jstl --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
  &lt;/dependency&gt;
  
          
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>