从JSP传递一个多维数组控制器 [英] Pass a multidimensional array from jsp to controller

查看:113
本文介绍了从JSP传递一个多维数组控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造我在哪里使用jQuery创建一个2维数组其中包括更新propertyName的和旧值的更新页面。我这样做,这样我就不需要检查服务器更新的属性。这updatedParam变量我需要通过它来春天控制器。应如何做?这个变量是不是模型支持表单的一部分。

我试图在控制器下面,但它不工作

  @RequestMapping(值=/updateEmployee.html,方法= RequestMethod.POST)
公共字符串updateEmployee(
        BindingResult结果,@ModelAttribute(雇员)员工的员工,
        ModelMap模式,
        @ModelAttribute(值=updatedParam)地图<字符串,字符串> updatedParam){

我甚至试过,但即使不工作

  @RequestMapping(值=/updateEmployee.html,方法= RequestMethod.POST)
公共字符串updateEmployee(
        BindingResult结果,@ModelAttribute(雇员)员工的员工,
        ModelMap模式,
        @ModelAttribute(值=updatedParam)的String [] [] updatedParam){

请注意:updatedParam是我在JSP和我想的时候产生的,我呼吁表单提交这一行动来传递变量

另外请注意表单提交code

  $(#updateEmployeeForm)。递交(函数(){
    //计算updatedParam这里
    //我试过用ajax submiting的形式,并通过更新的参数数据,但不工作});

请指教。在Firebug控制台我不断收到以下错误消息,但我不认为它与此相关的


  

HTML文档的字符编码​​未声明。该文件将在某些浏览器配置,乱码的文本渲染,如果文档包含来自US-ASCII范围之外的字符。页面的字符编码​​必须在文件中或在传输协议中声明。



解决方案

  

我这样做,这样我就不需要检查服务器更新的属性。


这是错误的。

您应该的总是检查由用户发送服务器的一切。结果
客户端验证是不充分的,因为客户机可以轻松地骗过了。

我建议你仅仅是为了让 propertyName的表单支持对象的一部分,并验证服务器端。

I am creating an update page where I am using jquery to create an 2 dimensional array which consists of updated propertyName and the old value. I am doing this so that I do not need to check on server for updated properties. This updatedParam variable I need to pass it to Spring controller. How should this be done? This variable is not part of the model backed form.

I have tried the following in the controller, but it does not work

@RequestMapping(value = "/updateEmployee.html", method = RequestMethod.POST)
public String updateEmployee(                       
        BindingResult result, @ModelAttribute("employee") Employee employee,
        ModelMap model,
        @ModelAttribute(value = "updatedParam") Map<String,String> updatedParam) {

I even tried this but even it does not work

@RequestMapping(value = "/updateEmployee.html", method = RequestMethod.POST)
public String updateEmployee(                       
        BindingResult result, @ModelAttribute("employee") Employee employee,
        ModelMap model,
        @ModelAttribute(value = "updatedParam") String[][] updatedParam) {

NOTE: updatedParam is the variable which I generated in my jsp and which I wish to pass when I call this action on form submission.

Also please note the form submission code

$("#updateEmployeeForm").submit(function(){
    //Compute updatedParam Here
    // I tried submiting the form using ajax and passing updated param as data but does not work 

});

Please advise. In firebug console I keep getting the following error message but I do not think its related to this

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

解决方案

I am doing this so that I do not need to check on server for updated properties.

This is wrong.

You should always check on server everything that is send by user.
Client side validation is not sufficient, as client can easily fool it.

What I'd recommend is simply to make propertyName a part of form backing object and validate it server side.

这篇关于从JSP传递一个多维数组控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆