Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringMVC表单选择选项_Spring_Jsp_Model View Controller - Fatal编程技术网

SpringMVC表单选择选项

SpringMVC表单选择选项,spring,jsp,model-view-controller,Spring,Jsp,Model View Controller,简单的SpringMVC应用程序。我想在我的JSP中填充一个表单:select,并在我的控制器中填充一个映射 在我的JSP中,表单:select没有任何选项。如果我从chrome中检查HTML元素,则没有选项。在我的项目的其他地方,同样的方法也适用,但在这种情况下,它是一个枚举 下面是简短的代码片段: // Domain Class public class Expense { String attributeSelectedFromJSP;

简单的SpringMVC应用程序。我想在我的JSP中填充一个表单:select,并在我的控制器中填充一个映射

在我的JSP中,表单:select没有任何选项。如果我从chrome中检查HTML元素,则没有选项。在我的项目的其他地方,同样的方法也适用,但在这种情况下,它是一个枚举

下面是简短的代码片段:

//        Domain Class          
public class Expense {
      String attributeSelectedFromJSP;
      Map<String,String> attributesToBeShownInJSP;
      ...
}
在我的JSP中

<form:form method="POST" action="/addNewExpense"
                modelAttribute="expense">
                <div class="form-group">
                    <table >
                    <tr>                    
                        <td>
                            <form:label path="attributeSelectedFromJSP">Select something: </form:label>
                        </td>
                        <td colspan="2">                    
                            <form:select path="attributeSelectedFromJSP" class="form-control">          
                                 <form:options items="${attributesToBeShownInJSP}" />
                            </form:select>
                        </td>
                    </tr>

选择一些:

对于同一类,其他字符串属性将正确显示。问题仅限于选择选项。同样的代码片段在我使用枚举的另一个屏幕上也可以正常工作。

您能试试这个吗?这可能有用

<c:set var="entry" value="${expense.attributesToBeShownInJSP}"></c:set>

设置映射,然后用映射对象填充选项标记

<form:select path="attributeSelectedFromJSP" class="form-control">          
    <form:options items="${entry}" />
</form:select>

为什么在Bean费用中声明map(map attributestobeshowinjsp):
这样做
1.
在控制器中,添加:
@ModelAttribute(“myMap”)
公共映射refData(){
地图。。。;
返回图;
}
2.
在jsp中

我认为您需要为AttributesTobeShowInJSP创建一个新的映射。然后您应该将其添加到模型中,并调用from items属性。
<form:select path="attributeSelectedFromJSP" class="form-control">          
    <form:options items="${entry}" />
</form:select>
Why u declare map (Map<String,String> attributesToBeShownInJSP)  in Bean Expense :

Do this 
1.
In controller, add  : 

 @ModelAttribute("myMap")
    public Map<String,String> refData() { 
        Map<String,String> map ...;

        return map;

    }

2.
in jsp

<form:form method="POST" action="/addNewExpense"
                modelAttribute="expense">

<form:select path="attributeSelectedFromJSP" class="form-control">          
         <form:options items="${myMap}" />
</form:select>

</form:form>