Reputation: 21
I have created a jsp page in a spring boot application that has got multiple forms in a single table. Each form having its own submit button. In each form I have kept an input element of type hidden with a value that I need to pass to the Controller class as a Request Parameter. So the form looks something like this:
<form action="getNode" method="get">
<input type="hidden" id="nodeId" value="${nodeid}">
<table>
<!-- Displaying node related data -->
</table>
</form>
The controller class has the request mapped as follows:
@RequestMapping(value="/getNode", method=RequestMethod.GET)
public String monitor(ModelMap model, @RequestParam("nodeId") String nodeId)
{
model.put("selectedNodeId", nodeId);
return "getNode";
}
When I run the Spring application and click on the form button I get the following exception on the console: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'nodeId' is not present
I am now getting confused as to how the value from the form is passed to the controller class. I tried using @ModelAttribute too, but am getting the same error. I also tried using POST method but no success. I basically do not want to show the values submitted through the form in my browser URL. So looking for other options.
Upvotes: 1
Views: 4617
Reputation: 21
It was a silly mistake from my side. Instead of assigning the input hidden type a name, I gave it an id. Hence the controller was not able to pick the parameter. Once I changed the id to name, it worked!
Upvotes: 1