title: SpringMVC - Pass object created in POST to the get method (show results of search on the same page)
body: <p>I'm a bit of a newbie in JEE and I'm trying to make a search page in my WebService, I use SpringMVC and I can search and get results in my controller (when I call a POST on my view) but I can't pass the object containing the results to the GET method of my controller.</p>
  
  <p>Here are my controller methods :</p>
  
  <pre><code>@RequestMapping(value = "/search", method = RequestMethod.GET)
  public String searchPage(ModelMap model) {
      String movie = null;
      model.addAttribute("movie", movie);
      return "search";
  }
  
  
  @RequestMapping(value = "/search", method=RequestMethod.POST)
  public String searchMovie(@RequestParam String movie, ModelMap model) throws IOException {
      movieService.setMovieName(movie);
      BaseResultsPage&lt;BaseMovie&gt; searchResults = movieService.movieSearch();
      System.out.println("search :" +searchResults.page);
      model.addAttribute("search_results", searchResults);
  
      return "search";
  }
  </code></pre>
  
  <p>I want to access the object in the following view :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"/&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"/&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"/&gt;
      &lt;meta name="description" content=""/&gt;
      &lt;meta name="author" content=""/&gt;
      &lt;link rel="icon" href="../../favicon.ico"/&gt;
      &lt;title&gt;Sign up&lt;/title&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
            integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
            crossorigin="anonymous"&gt;
      &lt;!-- Custom styles for this template--&gt;
      &lt;link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css"/&gt;
      &lt;script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;header&gt;
      &lt;h3&gt;Search Movies&lt;/h3&gt;
  &lt;/header&gt;
  &lt;c:url var="loginUrl" value="/login" /&gt;
  &lt;form action="${searchUrl}" method="post"&gt;
      &lt;div class="group"&gt;
          &lt;input type="text" id="movie" name="movie"/&gt;
          &lt;span class="highlight"&gt;&lt;/span&gt;
          &lt;span class="bar"&gt;&lt;/span&gt;
          &lt;label&gt;Movie Title&lt;/label&gt;
      &lt;/div&gt;
      &lt;input type="hidden" name="${_csrf.parameterName}"  value="${_csrf.token}" /&gt;
      &lt;div class="form-actions"&gt;
          &lt;input class="btn btn-primary" type="submit" value="Search"/&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;div&gt;
      &lt;c:if test="${seach_results == null}"&gt;
      &lt;table style="border-collapse: collapse;" border="1" class="showResults"&gt;
          &lt;tr&gt;
              &lt;td colspan="7"&gt;No Results found&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/c:if&gt;
      &lt;c:if test="${seach_results != null}"&gt;
      &lt;table style="border-collapse: collapse;" border="1" class="showResults"&gt;
          &lt;tr&gt;
              &lt;td colspan="7"&gt;Result found&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/c:if&gt;
  &lt;/body&gt;
  &lt;script&gt;
      $(document).ready(function() {
          $('input').blur(function () {
              var $this = $(this);
              if ($this.val())
                  $this.addClass('used');
              else
                  $this.removeClass('used');
          });
      });
  &lt;/script&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want to be able to access <code>searchResults</code> inside the view (and detect if its empty).</p>
  
  <p>Thx for your help !</p>