如何将Javascript数组传递给Spring Controller类
How to pass a Javascript array to the Spring Controller Class
我创建了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
}
尝试使用List<String>
而不是String[]
您必须在注释中指定请求参数的名称:
@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
}
相关文章:
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- 如何使用Spring MVC将Facebook返回的响应数据保存在Java类中
- 在MVC 4中,对Controller的Ajax调用为空
- spring和angularJS(我得到了类似HTTP状态404的错误)
- Spring Ajax列表返回,但对象为空
- 使用 JQUERY AJAX (Spring MVC) 从控制器中删除
- 用Java/Struts/Spring项目实现Visual Captcha
- 带有Spring的$.getJSON未执行回调
- 调用laravel{{action(Controller@method}}通过传递vue.js数组中的变量
- Spring WebFlow2 Javascript只在第一个单选按钮上工作
- 跨源请求阻止Spring REST服务+AJAX
- 基于用户加载不同的controller/js文件'访问级别
- Spring MVC:如何在Javascript中访问modelAndView XML对象
- Reveal Modal中带有Foundation-Controller的AngularJS不起作用
- 如何为通过ng-view指令或ng-controller指令创建的每个新作用域设置侦听器
- 打印从Spring MVC Controller发送的字符串数组只显示“;toJSON”;在javascript中
- 406向Spring Controller发送JSON时出错
- 如何将Javascript数组传递给Spring Controller类
- 将AJAX从Javascript发送到Spring Controller
- Jquery对话框——基于提交给Spring Controller的json,返回一个视图