If I have a Spring form as follows:
<c:url value="/user/profile?id=${user.id}" var="profileURL" />
<form:form action="${profileURL}" method = "get">
<input type="submit" value="My profile">
</form:form>
Spring complains that:
Your page request has caused a MissingServletRequestParameterException: Required String parameter 'id' is not present error:
However, in the controller method, the parameter is present:
@RequestMapping(value = "/profile", method = RequestMethod.GET)
public String getProfile(@RequestParam("id") String id, Model model) {
User user = userService.get(Integer.parseInt(id));
model.addAttribute("user", user);
return "profile";
}
Can anyone advise why this is?
If I use a simple form field like:
<input name="id" type="hidden" value="=${user.id}">
Everything is good. But I prefer to use a Spring field, hidden of necessary.
At run-time the form looks like this:
<form id="command" action="/nameOfapplication/user/profile?id=3" method="get">
<input type="submit" value="My profile">
</form>
This causes the following messages in the stacktrace:
Your page request has caused a MissingServletRequestParameterException: Required String parameter 'id' is not present error:
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255)