I am trying to get multiple path variables into a spring mvc controller but I am getting the following error
Error:
SEVERE: Servlet.service() for servlet [stp] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public java.lang.String edu.bnu.fyp.stp.web.controller.WatchlistController.saveWatchlist java.lang.String,java.lang.String,org.springframework.validation.BindingResult,org.springframework.web.bind.annotation.ModelAttribute,javax.servlet.http.HttpSession)] with root cause java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public java.lang.String edu.bnu.fyp.stp.web.controller.WatchlistController.saveWatchlit(java.lang.String,java.lang.String,org.springframework.validation.BindingResult,org.springframework.web.bind.annotation.ModelAttribute,javax.servlet.http.HttpSession)
Here is what I am trying to do
Controller:
@RequestMapping(value = "/add/{tutorId}/{studentId}" , method = RequestMethod.GET)
public String saveWatchlist(@PathVariable(value = "tutorId") String tutorId, @PathVariable(value = "studentId") String studentId , BindingResult bindingResult, ModelAttribute model, HttpSession session) {
System.out.println("Tutor ID is: " + tutorId);
System.out.println("Student ID is: " + studentId);
return "StudentWatchlist";
}
JSP:
<a href="${pageContext.request.contextPath}/watchlist/add/${tutorList.userId}/${sessionScope.user.userId}"> Add </a>
Note:
This URL is working and in JSP you can actually see the URL calling the controller with both IDs in the link. But for some reason, I am not able to catch these values in the controller. I have also tried the RequestParm solution, it didn't work either.