【发布时间】:2013-08-13 18:32:15
【问题描述】:
我创建了 JS 数组并尝试将数组传递给 Controller 类,但那里显示的是 NullPointerException。
我通过 FireBug 检查了 URL,那里的值正在传递,但在控制器类中,如果我尝试检索它显示为 NULL。
JavaScript 代码:
var deleteWidgetId = new Array(); //array created
deleteWidgetId[0] = "a";//adding values
deleteWidgetId[1] = "b";
//action trigged
$("#saveLayout").load("layout/saveLayout.action",
{ deleteWidgetId : deleteWidgetId },
function(response, status, xhr) { });
Java 代码(在控制器类中):
@RequestMapping(value = "/saveLayout")
public ModelAndView saveLayout(@RequestParam String[] deleteWidgetId) throws Exception {
//here that if i try to use the deleteWidgetId it is giving null pointer exception
}
【问题讨论】:
-
JavaScript 代码: var deleteWidgetId = new Array(); //创建数组 deleteWidgetId[0] = "a";//添加值 deleteWidgetId[0] = "b"; //动作触发 $("#saveLayout").load("layout/saveLayout.action", { deleteWidgetId : deleteWidgetId }, function(response, status, xhr) { });
-
Java 代码:(在控制器类中) @RequestMapping(value = "/saveLayout") public ModelAndView saveLayout(@RequestParam String[] deleteWidgetId) throws Exception { //这里如果我尝试使用deleteWidgetId它会给出空指针异常}
标签: java javascript spring spring-mvc