我正在尝试通过 JavaScript 将字段的值发送到 Struts2 后端,但它返回NullpointerException
.
<input type="hidden" id="employee.payslip.id" name="employee.payslip.id" value="5"/>
....
提交表单后,请求将被发送到以下 JavaScript 方法以发送到后端。
function payslipPayment(){
var formValues = $('#myform').serialize();
....
xmlhttp.open("get","../payslip/pay?"+formValues,false);
xmlhttp.send();
}
请求将按如下方式创建和发送
http://localhost/payslip/pay/employee.payslip.id=5&employee.payslip.year=2013&....
但是在后端,当我尝试显示它返回的值时NullPointerException
。
爪哇:
public class payslip {
private Employee employee;
public String pay{
System.out.println("Id:"+employee.payslip.id):
System.out.println("Year:"+employee.payslip.year;
...
}
getter and setter
}
课程:
public class Employee {
private Payslip payslip;
....
getter and setter
}
public class Payslip{
private long id;
...
getter and setter
}