I am very new to Spring MVC and am seeing a rather trivial behavior I don’t understand.
Bellow you can find snippets to my Controller (consider I have feed.jsp and feedList.jsp). What I don’t understand is why I need the “../list” in one redirect, when the other works without it
@Controller
@RequestMapping("/feed/*")
public class FeedController {
@RequestMapping(value = "delete/{feedId}", method = RequestMethod.GET)
public String deleteFeed(@PathVariable("feedId") Integer feedId) {
feedService.delete(feedId);
return "redirect:../list";
}
@RequestMapping(value = "save", method = RequestMethod.POST)
public String saveFeed(@ModelAttribute("feed") Feed feed, BindingResult result) {
feedService.create(feed);
return "redirect:list";
}
}
Perhaps the
UrlBasedViewResolveris handling view names as relative to the current request mapping url (citation needed).Anyway, I always use context-relative absolute paths (starting with a slash):
redirect:/list. Actually, if your jsp is called “feedList”, then your should returnredirect:/feedList