2

我创建了 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
}
4

2 回答 2

1

您必须在注解中指定请求参数的名称:

@RequestMapping(value = "/saveLayout")
public ModelAndView saveLayout(@RequestParam(value="deleteWidgetId") String[] deleteWidgetId) throws Exception { 
    //here that if i try to use the deleteWidgetId it is giving null pointer exception
}
于 2013-08-13T06:47:58.917 回答
1

尝试使用List<String>而不是String[]

于 2013-08-12T12:36:25.050 回答