Spring MVC checking user password

I am Trying to check the user is already registered or not as well as the password is correct or not but i am getting error as i mentioned down here is the both controller ->
@GetMapping("/login")
public String loginPage(Model model) {
model.addAttribute("movieFinderLoginUserPojo", new MovieFinderLoginUserPojo());
return "login";
}


@PostMapping("/loggedIn")
public String loggedInUser( @Valid @ModelAttribute("MovieFinderLoginUserPojo") MovieFinderLoginUserPojo movieFinderLoginUserPojo , BindingResult bindingResult , HttpSession httpSession , Model model) {

if(bindingResult.hasErrors())
{
System.out.println(bindingResult.getErrorCount());
return "login";
}

try {
String email = movieFinderLoginUserPojo.getEmail();

MovieFinderUser existingUser = finderUserImp.findByEmail(email);

if(existingUser!=null && existingUser.getPassword().equals(movieFinderLoginUserPojo.getPassword())){
httpSession.setAttribute("isLoggedIn", true);
System.out.println("The Email and Password is Correct ");
return "redirect:/home"; // Redirecting to the home page
}

else {
model.addAttribute("error", "Invalid email or password.");
return "login";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
return "login";
}
}




@GetMapping("/login")
public String loginPage(Model model) {
model.addAttribute("movieFinderLoginUserPojo", new MovieFinderLoginUserPojo());
return "login";
}


@PostMapping("/loggedIn")
public String loggedInUser( @Valid @ModelAttribute("MovieFinderLoginUserPojo") MovieFinderLoginUserPojo movieFinderLoginUserPojo , BindingResult bindingResult , HttpSession httpSession , Model model) {

if(bindingResult.hasErrors())
{
System.out.println(bindingResult.getErrorCount());
return "login";
}

try {
String email = movieFinderLoginUserPojo.getEmail();

MovieFinderUser existingUser = finderUserImp.findByEmail(email);

if(existingUser!=null && existingUser.getPassword().equals(movieFinderLoginUserPojo.getPassword())){
httpSession.setAttribute("isLoggedIn", true);
System.out.println("The Email and Password is Correct ");
return "redirect:/home"; // Redirecting to the home page
}

else {
model.addAttribute("error", "Invalid email or password.");
return "login";
}
}
catch (EmptyResultDataAccessException e ) {
e.getMessage();
return "login";
}
}




The errror :
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'movieFinderLoginUserPojo' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153)
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'movieFinderLoginUserPojo' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153)
3 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader6mo ago
I think you twisted the URLs.
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server