My jsp code:

        var mobileNumber = $("#mobileNumber").val();
        var userBO = {};
        userBO.firstName = Name;
        userBO.email = Email;
        userBO.password = "nmkkannan";
        userBO.gender = Gender;
        userBO.mobileNumber = mobileNumber;
        var userBo = JSON.stringify(userBO);
        $.ajax({
                        url : "../user/addUser",
                        type : "post",
                        dataType : "json",
                        contentType : "application/json; charset=utf-8",
                        data : userBo,
                        success : function(data) {
                            alert(data);
                        }
                    }); 

My controller :

           @RequestMapping(value = { "/addUser" }, method = RequestMethod.POST)
           public ModelAndView addUser(@ModelAttribute("userbo") UserBO userBO, BindingResult   result) {
           log.info("user first name and last name   " + userBO.getFirstName() + " " + userBO.getLastName());
           ModelAndView modelView = new ModelAndView("emailVerification");
           String encodedPassword = bCryptPasswordEncoder.encode(userBO.getPassword());
           userBO.setPassword(encodedPassword);
           try {
           manageUserServiceImpl.addUser(userBO);
           } catch (UserServiceException uSerExp) {
           log.error("Adding new user failed", uSerExp);
           modelView.setViewName("registration");
           modelView.addObject("messsage", "Application error, Please Try again");
           return modelView;
           }
          log.info("user added successfully");
           return modelView;
           }

UserBO is object that contain variables with getter and setter method.

My problem is i want to pass values from jsp (userbo) to controller but i get userbo null. I got null pointer error in my jboss. How to pass values object in jsp to controller? How to solve it?

Related posts

Recent Viewed