exception org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是java.lang.NullPointerException

时间:2016-04-01 17:44:58

标签: java spring

<div class="secondForm">
    <div class="registerForm" align="center">
    <form:form method="post" action="/InvoiceProject/addUser" >
    <table align="center">
        <tr> 
            <td colspan="2" > <h2>New User? Sign-Up. </h2> </td>

        </tr>
        <tr>

            <td> <form:label path="firstName">  First Name: </form:label>  </td>
            <td> <form:input path ="firstName" type="text"  name = "firstName" id="firstName" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="lastName" >  Last Name: </form:label>  </td>
            <td> <form:input path ="lastName"  type="text"  name = "lastName" id="lastName" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="email" >  Email: </form:label>  </td>
            <td> <form:input path ="email"  type="email"  name = "emailAddr" placeholder="xyz@example.com" id="emailAddr" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="password" >  Password: </form:label>  </td>
            <td> <form:input path ="password"  type="password"  name = "newPassword" id="newPassword" required="required"/> </td>
        </tr>
        <tr>
            <td> <label>  Re-Enter Password: <label>  </td>
            <td> <input type="password"  name = "confirmPassowrd" id="confirmPassowrd" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="city" >  City: </form:label>  </td>
            <td> <form:input path ="city"  type="text"  name = "city" id="city" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="zipCode" >  ZIP-CODE: </form:label>  </td>
            <td> <form:input path ="zipCode"  type="text"  name = "zipCode" id="zipCode" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="state" >  State: </form:label>  </td>
            <td> <form:input path ="state"  type="text"  name = "state" id="state" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="country" >  Country: </form:label>  </td>
            <td> <form:input path ="country"  type="text"  name = "country" id="country" required="required"/> </td>
        </tr>
        <tr>
            <td> <form:label path ="phoneNumber" >  Phone Number: </form:label>  </td>
            <td> <form:input  path ="phoneNumber" type="text"  name = "phoneNumber" id="phoneNumber" placeholder="(+91-987654321)" required="required"/> </td>
        </tr>
        <tr> 
            <td> <input type="submit" value="Register" id="RegisterForm"/> </td>
            <td> <input type="reset" value = "Cancel" /> </td>
        </tr>
        </table>
    </form:form>

这是我的register.jsp页面。如果我添加commandName然后在控制器中使用命令名并执行,则会抛出一个错误,指出绑定结果都不是bean xxx可用的普通目标对象。

@Controller
public class LoginOrRegisterController {
CustomerVO cust = null;
RegisterUserService registerUserService;
Integer  id = null;


@RequestMapping(value="/Login", method=RequestMethod.GET)
public String viewForm(ModelMap model){
    cust = new CustomerVO();
    model.addAttribute("command", cust);
    return "loginOrRegister";
}




@RequestMapping(value="/addUser", method=RequestMethod.POST)
public String addUser(@ModelAttribute("command") CustomerVO customer, ModelMap model){
    //cust.setFirstName(customer.getFirstName());
    id = registerUserService.RegisterUser(customer);
    System.out.println(id);
    return "";

}

这是我的控制器类。 RegisterUSer(客户)会抛出错误;

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试自动装配您的RegisterUserService,如下所示:

@Controller
public class LoginOrRegisterController {
    CustomerVO cust = null;
    @Autowired RegisterUserService registerUserService;
    Integer  id = null;
    /*...*/