Reputation: 3274
I want to send selected options of a select to controller using following
<form action="/save" method="POST" >
<input type="text" name="name"/>
<label>Subjects</label>
<select name="subjects">
<option value="English">English</option>
<option value="Maths">Maths</option>
</select>
<input type="submit" value="Save">
</form>
In controller while form is posted I check the size of subjects list
@RequestMapping(params={"subjects"}, value = "/save-std", method = RequestMethod.POST)
public String saveStd(@ModelAttribute("std")Student std,
@RequestParam("subjects") List<String> subjects) {
System.out.println("List Size is " + subjects.size() );
return "home";
}
it always shows List Size is 1
in the console, why it happens or any better solution to get all selected options?
Upvotes: 0
Views: 111
Reputation: 368
Please refer to this link. This may help you.
"Request parameters are a Multimap of String to String. You cannot pass a complex object as request param."
Upvotes: 1