简体   繁体   English

如何从Spring控制器中发布表单获取动态值

[英]how to get dynamic values from posting a form in the Spring controller

I am creating a form dynamically, and I need to post it and get the values in SpringController 我正在动态创建一个表单,我需要发布它并在SpringController中获取值

    for(var i=0;i<datArray.length;i++){
        element[i] = document.createElement("input");
        element[i].setAttribute("type", "text");
        element[i].setAttribute("name", "text");
        element[i].setAttribute("placeholder",datArray[i]);
        element[i].setAttribute("id", datArray[i]+"id");
        var foo = document.getElementById("fooBar");        
        //Append the element in page (in span).
        foo.appendChild(element[i]);
}   

这是我在Select onChange中绘制的动态表单。

About Pic - this is my dynamic form drawn in Select onChange 关于Pic-这是我在Select onChange中绘制的动态表单

On Every dropdown Changed I am generating different text boxes dynamically. 在每个下拉列表更改时,我正在动态生成不同的文本框。 I need to post the dynamic text boxes and get the values in the Controller Spring in JAVA. 我需要发布动态文本框并在JAVA的Controller Spring中获取值。 How to get dynamically posted Values in controller? 如何在控制器中动态发布值?

Any Idea? 任何想法?

Are you always sending the same model Object? 您是否总是发送相同模型的对象? I mean, does your form element always has the same name attribute? 我的意思是,您的表单元素是否始终具有相同的name属性?

if yes, you can just create a pojo class with attributes maching your names and use a RequestAttribute annotation. 如果是的话,您可以只创建一个带有属性的pojo类,该属性可以缓存您的姓名并使用RequestAttribute批注。

If no, there is no way, you will just have to use the old requestparameter. 如果没有,那就没有办法了,您只需要使用旧的request参数即可。

UPDATE If you dont know what parameters are submitted, loop into all parameters : 更新如果您不知道要提交什么参数,请循环进入所有参数:

    List<String> requestParameterNames = Collections.list((Enumeration<String>) request.getParameterNames());

for (String parameterName : requestParameterNames) {
    String attributeName = parameterName;
    String attributeValue = request.getParameter(parameterName);

    //DO YOUR STUFF
}
//DO YOUR STUFF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spring MVC 4上将JSP中的表单值发布到控制器时解决ClassCastException - How to solve ClassCastException while posting my form values from jsp to controller on spring mvc 4 表单未将数据发布到Spring Controller - Form not posting data to Spring Controller 如何从Spring MVC中动态创建的表单中获取Controller内部参数的值 - how to get values of parameters inside Controller from a dynamically created form in spring MVC 从Spring Controller访问GWT表单值 - Access GWT Form Values from Spring Controller 春天如何从控制器中的表单获取输入日期? - How can I get an input date from a form in a controller in spring? 如何获取jsp页面中的值以从spring控制器返回? - how to get values in jsp page to return from spring controller? 在提交时将多个值从spring表单jsp传递给spring控制器 - Pass multiple values from spring form jsp to spring controller on submit 如何通过Spring(3)控制器操作方法打印出未声明的HTML表单值? - How can you print out the values of undeclared HTML form values from a Spring (3) controller action method? 如何使用Spring MVC从表单中的合成中获取属性值 - How to get attribute values from a composition in the form with Spring MVC 将JSON发布到Spring Controller - Posting a JSON to a Spring Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM