0

@Controller
public class UsersController

{
 

 @Autowired
 UsersService userServices;
 @RequestMapping(value="/page", method = RequestMethod.GET) /* whenever the client gives the url request "/page" it will run this method and shows the users.jsp page to the client */
 public ModelAndView getuserPage(){
  ModelAndView view =new ModelAndView("users");
  return view;
 }
 
 @RequestMapping(value="register" ,method = RequestMethod.POST )// whenever the client gives the url request "users/register" it will run this method and shows the users.jsp page to the client //
 public ModelAndView Registeruser(@RequestParam("user_name") String user_name, @RequestParam("user_contact") int user_contact,@RequestParam("user_email") String user_email, @RequestParam("user_password") String user_password)
 
 {
  Users usersobj=new Users(user_name, user_contact, user_email, user_password);
  
  ModelAndView modelview=new ModelAndView();
  
  if(userServices.saveOrUpdate(usersobj))
  {
  modelview.setViewName("users");
    return modelview;
  }
  else
  {
   modelview.setViewName("users");
    return modelview;
  }
  
 }
}
 /*
 @ModelAttribute("users_obj")
 public Users constructUser() {
  return new Users();
 }
 @RequestMapping(value="/register.html" ,method = RequestMethod.POST )// whenever the client gives the url request "users/register" it will run this method and shows the users.jsp page to the client //
 public ModelAndView Registeruser(@ModelAttribute("users_obj") Users users_obj) 
 {  
  ModelAndView modelview=new ModelAndView();
  if(userServices.saveOrUpdate(users_obj))
  {
  modelview.setViewName("users");
    return modelview;
  }
   modelview.setViewName("users");
   return modelview;
     }
}
<body>

<div id="login-form">
<!-- gives the toggle effect between login and register -->
<input type="radio" checked id="login" name="switch" class="hide">
<input type="radio" id="signup" name="switch" class="hide">
<!-- bootstrap icons that does not require download or install-->
<div>
<ul class="form-header">
<li><label for="login"><i class="fa fa-unlink"></i> LOGIN</label></li>
<li><label for="signup"><i class="fa fa-credit-card"></i> REGISTER</label></li>
</ul>
</div>

<div class="section-out">
<section class="login-section">
<div class="login">
<form action=""> <!-- on login i have to put the url of the backend class to handle it -->
<ul class="ul-list">
<li><input type="email" required class="input" placeholder="Email ID" id="email"/><span class="icon"><i class="fa fa-user-secret" style="font-size:20px"></i></span></li>
<li><input type="password" required class="input" placeholder="Password" id="pass"/><span class="icon"><i class="fa fa-lock" style="font-size:20px"></i></span></li>
<li><span class="remember"><input type="checkbox" id="check"> <label for="check">Remember Me</label></span><span class="remember"><a href="">Forgot Password</a></span></li><!-- on forgot password i have to put the url of the backend class to handle it -->
<li><input type="submit" value="SIGN IN" class="btn" onclick="validate()"/></li>
</ul>
</form>
</div>

</section>

<section class="signup-section">
<div class="login">
<form action="register" method="post"><!-- on registration i have to put the url of the backend class to handle it -->
<ul class="ul-list">
<li><input type="text" required class="input" placeholder="Your Name" id="R_name" name="user_name"/><span class="icon"><i class="fa fa-user" style="font-size:20px"></i></span></li>
<li><input type="number" required class="input" placeholder="Your Number (no plus or minus signs)" id="R_number" name="user_contact" pattern="('^\\d+$')" title="Must contain only numbers" required/><span class="icon"><i class="fa fa-mobile-phone" style="font-size:25px"></i></span></li>
<li><input type="email" required class="input" placeholder="Your Email" id="R_email" name="user_email"/><span class="icon"><i class="fa fa-envelope" style="font-size:15px"></i></span></li>
 <li><input type="password"  placeholder="Password" required class="input"  id="R_pass" name="user_password" pattern="(?=.*?[0-9]).{8,}" title="Must contain at least one number and at least 8 or more characters" required/><span class="icon"><i class="fa fa-lock" style="font-size:20px" ></i></span></li>
<li><input type="password"  placeholder="Retype Password" required class="input"  id="Rc_pass"pattern="(?=.*?[0-9]).{8,}" title="Must contain at least one number and at least 8 or more characters" required/><span class="icon"><i class="fa fa-lock" style="font-size:20px" ></i></span></li>
<li><input type="checkbox" id="check1"> <label for="check1">I accept terms and conditions</label></li>
<li><input type="submit" value="SIGN UP" class="btn" onclick="validate2()"></li>
</ul>
</form>
</div>


</section>
</div>

</div>
</body>

Below are my controllerclass and users.jsp file in the users.jsp file i have different forms one is for login and another is for user registration purpose. I'm currently working on registration form and its relevant controller class and getting this error

I have tried with modelattribute too and got the same error message so tried with @requestparam and still getting same error, what am i doing wrong here i do have a javascript to force the client not give empty parameters I have users pojo and the service for saveorupdate class is as follows:

@Service
public class UsersServiceImpl implements UsersService{

    @Autowired
    UsersDao userDao;

    public boolean saveOrUpdate(Users users) {
        return userDao.saveOrUpdate(users);
    }

Could some one please help me point out whats wrong in this code what am i doing wrong, am i missing some configuration in pom.xml or front controller xml file ? I'm trying to fix this code for past 2 days and this is my last hope sure would appreciate if someone with knowledge point out what im doing wrong and how to fix this code.

Joao Vitorino
  • 2,641
  • 2
  • 29
  • 50
  • Check this question: https://stackoverflow.com/questions/17964841/how-to-get-param-in-method-post-spring-mvc – Alex Roig Jul 20 '18 at 16:00

1 Answers1

0

In your case request parameters mentioned in controller method are not present with the request.

Try getting paramters using request.getParameter("fieldName");

and check all the fields whether present or not along with the type int or string.

Alien
  • 13,439
  • 5
  • 35
  • 53
  • im terribly sorry about this but im still in learning phase in spring mvc could you please enlighten me more about how to use request.getParameter("fieldName") to check the fields present with request or not – mohamed faizal Jul 20 '18 at 16:38
  • In JSP page you are giving name to all the fields so in controller by passing the same names you can get all the parameters one by one for checking...just google about request.getparameter – Alien Jul 20 '18 at 16:40