title: Why won't my JSP page load when I call it via a method in my Controller class?
body: <p>I'm trying to pass two values from a method in my controller class to a JSP page, the functionality in the controller seems to work but the JSP page won't load. The two values are an <code>average house price</code> and an integer value representing the <code>number of houses</code> returned from a database query. I take in a latitude and longitude value from a <strong>different JSP page</strong> and they determine the values returned from the database. (I don't want to pass the <code>average house price</code> and <code>number of houses</code> values back to that same JSP page where the latitude and longitude originally came from, but a new page).</p>
  
  <p>In my controller class, I have a debug that prints the results from the database query successfully in my Eclipse console so I know the query works, I've also included a print statement to see if the <code>session</code> contains a value and it prints successfully. So it seems that the values are correct and ready to be sent to the <strong>new JSP page</strong> however the page I'm trying to load simply won't load and I've tried several different ways to fix this but none work (I'll go into these ways below).</p>
  
  <p>At the moment I'm trying to use <code>HttpSession</code> to pass the values from the controller to the <strong>new JSP page</strong> like so:</p>
  
  <pre><code>    @RequestMapping(value = "/parseHousePrice", method = RequestMethod.GET)
      public String parseHousePrice(@RequestParam("latitude") double latitude, 
                                    @RequestParam("longitude") double longitude,                                                            
                                    HttpSession session) {
  
      // This passes the lat &amp; long into a method that will query the database 
      // and store the result into the housePrice double varaible
      double housePrice = parseHousePrice.ParseHousePrice(latitude, longitude);
  
      // This gets the number of houses returned from the query
      // and stores it into the number_of_houses integer value 
      List&lt;Double&gt; housePriceList = parseHousePrice.getList();
      int number_of_houses = housePriceList.size();
  
      // Debug to show the query works successfullt
      System.out.println("The average house price for this area is: " + housePrice + " based on " + number_of_houses + " property prices in this area");
  
      // Assigning the values to session attributes 
      session.setAttribute("houseprice", housePrice );
      session.setAttribute("housepricelistsize", number_of_houses);
  
      // Debug that shows the session currently holds a value
      System.out.println(session.getServletContext());
  
      // New JSP page I want to pass the values to
      return "houseprice";
  }
  </code></pre>
  
  <p>In my <strong>new JSP page</strong> I try to pass the values from above into the following <code>&lt;p&gt;</code> tags:</p>
  
  <pre><code> &lt;p th:text="${session.houseprice}" th:unless="${session == null}"&gt;[...]&lt;/p&gt;
   &lt;p th:text="${session.housepricelistsize}" th:unless="${session == null}"&gt;[...]&lt;/p&gt;
  </code></pre>
  
  <p>Like I said above I've tried various methods of passing the values to the JSP page but none work and the page won't load.</p>
  
  <p>I've attempted to use a <code>model</code> to pass the values through like so:</p>
  
  <pre><code>    model.addAttribute("houseprice", housePrice);
      model.addAttribute("housepricelistsize", number_of_houses);
  </code></pre>
  
  <p>I printed the model as a debug using a simple <code>System.out.println(model);</code> and this printed the correct values and names of values.</p>
  
  <p>And I've attempted to create a <code>HousePriceObject</code> entity and create a list of these objects in the controller. I would then use a <code>ModelAndView</code> and return the name of the <code>ModelAndView</code> instead of the JSP page name (<code>houseprice</code>) at the end of the method in the controller class like so:</p>
  
  <pre><code>        ModelAndView map = new ModelAndView("houseprice");
          map.addObject("housepricesList", housepricesList);
  
          // Return the ModelAndView instead of "houseprice" JSP page
          return map;
  </code></pre>
  
  <p>And use a <code>&lt;c:forEach&gt;</code> loop to iterate through the list and print it on the JSP page but it still won't work.</p>
  
  <pre><code>&lt;table&gt;
  &lt;c:forEach items="${housepricesList}" var="HousePrice"&gt; 
      &lt;tr&gt;
          &lt;td&gt;&lt;c:out value="${HousePrice.housePrice}"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;c:out value="${HousePrice.number_of_houses}"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
   &lt;/c:forEach&gt;
  &lt;/table&gt; 
  </code></pre>
  
  <p>Am I missing something small here or am I going about this the completely wrong way. As I said the values seem to ready to be sent and I think they will print as soon as the page loads, but the page simply will not load. An advice would be appreciated!</p>
  
  <p><strong>Edit</strong> I have other JSP pages loading from the controller when the methods are called, however it seems the fact the particular method highlighted above has a lot more functionality (i.e. taking in data from one JSP page, querying the database, and printing the data to a new JSP page, etc) something stops the <code>houseprice</code> JSP page from opening. </p>
  
  <p>For example, the JSP page will open when I run the method above without all the extra code.</p>
  
  <pre><code>    @RequestMapping(value = "/parseHousePrice", method = RequestMethod.GET) 
  public String parseHousePrice(@Valid HousePrice housePriceObject, BindingResult bindingResult, Model model) {
  
      // houseprice.jsp will open but obviously has none of the data 
      return "houseprice";
  }
  </code></pre>