title: Spring MVC, how to pass a parameter to thymeleaf view when redirecting
body: <p>I am using Spring MVC and thymeleaf in my web application.</p>
  
  <p>In one of the scenario I have a controller which do a redirecting at end of its functionality. I need to pass a parameter (actually a success/fail alert message) to my front end. How can I implement this behavior.</p>
  
  <p>I could know that model.addAttribute() cannot be implemented when there is a redirection.</p>
  
  <p>Following is the controller code.</p>
  
  <pre><code>@RequestMapping(value = "delete", method = RequestMethod.GET)
  public ModelAndView deleteForm544(@RequestParam("id") final Long inForm544Id) {
  
      logger.info("Hit the /Form544/delete ");
      logger.info("Change Status Deleted of Form 544 ID : " + inForm544Id);
  
      JSONObject alertObj = new JSONObject();
  
      try {
          form544Service.setStatusAsDeleted(inForm544Id);
  
          alertObj.put("type", "success");
          alertObj.put("msg", "Successfully deleted Form 544 with ID Number " + inForm544Id);
  
      } catch (Exception e) {
          logger.error("Error occured " + e);
  
          alertObj.put("type", "fail");
          alertObj.put("msg", "Form 544 deletion failed. Due to " + e.getMessage());
      }
  
      return new ModelAndView("redirect: filter_view");
  }
  </code></pre>
  
  <p>Following is the view(thymeleaf) code. [Note: I need to get the value to a javascript variable]</p>
  
  <pre><code>&lt;script th:inline="javascript"&gt;
  
      /*&lt;![CDATA[*/
      var alertObj = ([[${alert}]]);
      /*]]&gt;*/
  
  &lt;/script&gt;
  </code></pre>