I am building a website using spring mvc. Just I built the login screen and the related controllers and services.
Now when validating the user credentials if the given password is wrong then it should navigate back to the login.jsp page. If the inputs are correct then it should navigate to userHomepage.jsp page.
I have done this as below,
try {
loginService.checkUserValidity(userId, password);
return new ModelAndView("userHomePage"); //if all the user credentials are good then redirect the user to User Home Page
} catch (UserNotExistsException e) {
loginResult = e.toString();
return new ModelAndView("login", "loginResult", loginResult);
} catch (InvalidPasswordException e) {
loginResult = e.toString();
return new ModelAndView("login", "loginResult", loginResult);
}
In the above code snippet I was hardcoding the navigating pages file names in ModelAndView (like login, userHomePage etc.,).
Is it correct approach to hardcode them? Is it possible to specify the page navigation using some properties kind of file in spring MVC like in JSF? Is spring MVC webflow sole purpose that?
Thanks
It’s not unusual to hae the views specified as you have them.
If you have complex navigation you wanr to specify in an XML file, like JSF, Spring Webflow is for you. It can be tricky to set up, but provides a nice framework for complex navigation.