I have a user controller. It has three methods for listing users, showing a user add page and saving a user. When the user is saved, it should redirect to the user listing page.
In my case when I try to do the redirect, I am getting the following error.
No mapping found for HTTP request with URI [/myApp/cases/cases] in DispatcherServlet
Below is my entire UserController.
@Controller
@RequestMapping("/users")
public class UserController extends BaseController {
private static Logger logger = Logger.getLogger(userController.class);
@RequestMapping(method = RequestMethod.GET)
public ModelAndView list() {
logger.info(" [list] - showing user list.");
ModelAndView mav = new ModelAndView("userList");
mav.addObject("users", new ArrayList<User>());
return mav;
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public ModelAndView form() {
logger.info(" [form] - showing new user creation form.");
ModelAndView mav = new ModelAndView("userForm");
mav.addObject("user", new User());
return mav;
}
@RequestMapping(method = RequestMethod.POST)
public String save(User user) {
logger.info(" [save] - saving user.");
return "redirect:/users";
}
}
Am I doing the redirection proper way?
Add the context of DispatrcherServlet. For example, if URL pattern of dispatcher servlet (in web.xml) is ‘myApp’ then it should be:
return "redirect:/myApp/users";