title: Get form's multiple inputs with the same name in spring mvc
body: <p>I have some input fields in my jsp page, and the fields can be dynamically created or removed. So I have to map the input fields to spring mvc's @ModelAttributes. But I do not know how to map input fields.</p>
  
  <p>I want to submit a form that composed of:</p>
  
  <pre><code>&lt;form enctype="multipart/form-data"&gt;
      &lt;!-- code omitted --&gt;
  
      &lt;div&gt;
          &lt;input type="text" name="content"&gt;
          &lt;input type="file" name="file"&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="text" name="content"&gt;
          &lt;input type="file" name="file"&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="text" name="content"&gt;
          &lt;input type="file" name="file"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And that fields should be guided to the Java classe(@ModelAttribute):</p>
  
  <pre><code>package com.musicovery12.cookingstep.web.command;
  
  import java.util.Arrays;
  import java.util.List;
  
  
  public class AddRecipeCommand {
  
      private String mainImageUrl;
      private String foodName;
      private String kcal;
      private String ingredients;
      private String foodDescription;
  
      // I do not know how to map into this field.
      private List&lt;RecipeStep&gt; recipeSteps;
  
      private String videoUrl;
  
  
      public String getMainImageUrl() {
          return mainImageUrl;
      }
      public void setMainImageUrl(String mainImageUrl) {
          this.mainImageUrl = mainImageUrl;
      }
      public String getFoodName() {
          return foodName;
      }
      public void setFoodName(String foodName) {
          this.foodName = foodName;
      }
      public String getKcal() {
          return kcal;
      }
      public void setKcal(String kcal) {
          this.kcal = kcal;
      }
      public String getIngredients() {
          return ingredients;
      }
      public void setIngredients(String ingredients) {
          this.ingredients = ingredients;
      }
      public String getFoodDescription() {
          return foodDescription;
      }
      public void setFoodDescription(String foodDescription) {
          this.foodDescription = foodDescription;
      }
      public List&lt;RecipeStep&gt; getRecipeSteps() {
          return recipeSteps;
      }
      public void setRecipeSteps(List&lt;RecipeStep&gt; recipeSteps) {
          this.recipeSteps = recipeSteps;
      }
      public String getVideoUrl() {
          return videoUrl;
      }
      public void setVideoUrl(String videoUrl) {
          this.videoUrl = videoUrl;
      }
      @Override
      public String toString() {
          return "AddRecipeCommand [mainImageUrl=" + mainImageUrl + ", foodName="
                  + foodName + ", kcal=" + kcal + ", ingredients=" + ingredients
                  + ", foodDescription=" + foodDescription + ", recipeSteps="
                  + recipeSteps + ", videoUrl=" + videoUrl + "]";
      }
  }
  </code></pre>
  
  <p>That command class has a property that is not primitive type. It's RecipeStep:</p>
  
  <pre><code>package com.musicovery12.cookingstep.web.command;
  
  import org.springframework.web.multipart.MultipartFile;
  
  public class RecipeStep {
      private String content;
      private MultipartFile image;
  
      public RecipeStep() {}
  
      public String getContent() {
          return content;
      }
      public void setContent(String content) {
          this.content = content;
      }
      public MultipartFile getImage() {
          return image;
      }
      public void setImage(MultipartFile image) {
          this.image = image;
      }
  
      @Override
      public String toString() {
          return "RecipeStep [content=" + content + ", image=" + image + "]";
      }
  
  
  }
  </code></pre>
  
  <p>So my question is, 
  how to map the form's input fields into the above java class?
  is it possible by changing the name of input fields? then, how?</p>