How do make Spring access dropdown box values

时光毁灭记忆、已成空白 提交于 2020-01-17 09:01:44

问题


How do make Spring access dropdown box values.

I am trying to make Spring MVC get the value of one of my dropdowns.

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/view/dateRange.jsp at line 28

25: <tr>
26:     <td>
27:         <div align="right">Last Month Of Full Data:</div></td>
28:         <td><form:select path="Lst_mnt">
29:             <option value="1">January</option>
30:             <option value="2">February</option>
31: 

All that I am doing its to get the value into Spring not build the dropdown


回答1:


First of all, you are not using the <form:select> properly. You have two options:

  • use a simple <select> tag with <option> tags inside, and give it a name the corresponds to the model object field (Lst_mnt in this case, but avoid that underscore)
  • use <form:select> with a Map in which you can fill the keys and values for the select

Thus you will show the values. Then:

  • If you want to get the selected value - it will be filled in the model object when the form is submitted, so you will have it in your controller method.
  • If you want to manipulate them in the browser - use javascript



回答2:


If you remove the td that includes the form:select does your form work correctly?

Is Lst_mnt a property of the form backing bean? Also is it an integer or string field?

Maybe you can post the whole form?



来源:https://stackoverflow.com/questions/5968046/how-do-make-spring-access-dropdown-box-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!