title: How do I reset a ModelAttribute in Spring 3?
body: <p>I just started with Spring MVC so it's probably a rookie mistake.</p>
  
  <p>The ModelAttribute is reused every request. How can I make sure every POST starts with a clean object?</p>
  
  <p><strong>My controller</strong> (MyController.java):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Controller
  public class MyController {
  
    @RequestMapping(method = RequestMethod.POST)
    public String processChoice(@ModelAttribute("myData") MyData myData, BindingResult bindingResult) {
      System.out.println("POST: myData = " + myData);
      return "redirect:/myview?choice=" + myData.getChoice();
    }
  
    @RequestMapping(method = RequestMethod.GET)
    public String displayChoice(@RequestParam(required = false) String choice, Model model) {
      System.out.println("GET: Choice = " + choice);
      model.addAttribute("myData", new MyData(choice));
      return "myview";
     }
  
  }
  </code></pre>
  
  <p><strong>My view</strong> (myview.jsp):</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Spring Tests&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form:form modelAttribute="myData" method="POST"&gt;
        &lt;form:select path="choice"&gt;
          &lt;option&gt;&lt;/option&gt;
          &lt;option value="one"&gt;One&lt;/option&gt;
          &lt;option value="two"&gt;Two&lt;/option&gt;
        &lt;/form:select&gt;
        &lt;input type="submit" value="Choose"/&gt;
      &lt;/form:form&gt;
      &lt;c:if test="${not empty myData.choice}"&gt;Choice = ${myData.choice}&lt;/c:if&gt;
      &lt;c:if test="${empty myData.choice}"&gt;No choice&lt;/c:if&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Successive clicks on the "Choose" button appends the chosen values instead of just POST-ing the current one:</p>
  
  <pre><code>GET: Choice = null
  POST: myData = MyData [choice=two]
  GET: Choice = two
  POST: myData = MyData [choice=two,one]
  GET: Choice = two,one
  POST: myData = MyData [choice=two,one,]
  GET: Choice = two,one,
  POST: myData = MyData [choice=two,one,,one]
  GET: Choice = two,one,,one
  </code></pre>