I have some trouble forwarding after a request to a previous url.
I've got a team-page, (.../team/teamMembers/{id}
) in which all the team players from a team are listed. There is a delete button, to delete a team player from the team. After this request has been made, i want to return to the team/teamMembers/{id}
page again, which has now been edited.
My request looks like this:
@RequestMapping(value = "/deleteTeam/{id}", method = RequestMethod.GET)
public ModelAndView deleteTeam(@PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("/team/teamMembers/{id}");
memberService.deleteTeam(id);
List<Member> members = memberService.getMembers();
modelAndView.addObject("members", members);
String message = "Member was successfully deleted from team.";
modelAndView.addObject("message", message);
return modelAndView;
}
But of course, team/teamMembers/{id}
does not work, since {id} doesn't have a value, and is not a good url string. Furthermore, the id from the deleteTeam/{id}
is a memberID and not a teamID.
How can I redirect to the page from which the getRequest
has been made ?
You need to teamId also while deleting a member from team, because you will redirect again teamMembers page.
So that method will work as you wish.