Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created May 5, 2019 10:45
Show Gist options
  • Select an option

  • Save darbyluv2code/cd9cd2c01c4542d46e02c4e1f22fe678 to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/cd9cd2c01c4542d46e02c4e1f22fe678 to your computer and use it in GitHub Desktop.
duplicate form field names
package com.luv2code.springdemo.mvc;
import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/student")
public class StudentController {
@RequestMapping("/showForm")
public String showForm(Model theModel) {
theModel.addAttribute("student", new Student());
return "student-form";
}
@RequestMapping("/processForm")
public String processForm(@ModelAttribute("student") Student theStudent, HttpServletRequest request) {
System.out.println("List of parameters from HttpServletRequest");
Map<String, String[]> parameterMap = request.getParameterMap();
for (String tempParamName : parameterMap.keySet()) {
String[] tempParamVal = parameterMap.get(tempParamName);
System.out.println(tempParamName + " = " + Arrays.asList(tempParamVal));
}
System.out.println("\n\n");
System.out.println("Student Details : " + theStudent);
return "student-confirmation";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment