2

JSP

<select name="requirements"  style="width:150px;" id="requirements1">
                                        <option selected="selected" value="o Special Assistance">No Special Assistance</option>
                                        <option value="Assistance climbing steps">Assistance climbing steps</option>
                                        <option value="Assistance within the plane">Assistance within the plane</option>
                                        <option value="Blind passenger">Blind passenger</option>
                                        <option value="Hearing impaired">Hearing impaired</option>
                                        <option value="Wheelchair within terminal">Wheelchair within terminal</option>
                                    </select>
<select name="requirements"  style="width:150px;" id="requirements2">
                                        <option selected="selected" value="o Special Assistance">No Special Assistance</option>
                                        <option value="Assistance climbing steps">Assistance climbing steps</option>
                                        <option value="Assistance within the plane">Assistance within the plane</option>
                                        <option value="Blind passenger">Blind passenger</option>
                                        <option value="Hearing impaired">Hearing impaired</option>
                                        <option value="Wheelchair within terminal">Wheelchair within terminal</option>
                                    </select><input type="text" name="specialrequest" id="specialrequest1" />
        </form>

班级

public class PassengerDetailDTO {

    private String[] requirements;
    private String specialrequest;
}

并在控制器中

@RequestMapping(value = "/manualbooking.htm", method = RequestMethod.POST)
    public String doManualBooking(HttpServletRequest httpServletRequest,
            PassengerDetailDTO passengerDetailDTO,  ModelMap map) {
        LOGGER.info("Manual Booking Request");

        LOGGER.info(passengerDetailDTO.toString());

        return "manualbooking";
    }

当有多个下拉框时,提交表单后要求始终为空。如何解决?

4

2 回答 2

1

确保您的<select>盒子名称代表 array []。例如:

<select name="requirements[0]" ..>

<select name="requirements[1]" ..>

检查这个演示:Spring MVC Multi Row Form

于 2012-12-19T13:22:45.090 回答
-1

您可以将 2 个不同的字符串字段添加到您的支持 bean,即

private String requirement1;
private String requirement2;

然后使用类似于此的构造

 <form:select path="requirement1" multiple="false" id="requirement1">
    <form:options items="${yourRequirementsAsACollection}" />
 </form:select>


 <form:select path="requirement2" multiple="false" id="requirement2">
    <form:options items="${yourRequirementsAsACollection}" />
 </form:select>

将所选值分别写入第一个或第二个字段。

另一方面,您可以使用多选框,在这种情况下,所有选定的值最终将在单个字段中以逗号分隔。

 private String requirements; // Ends up comma-separated, ie "req1, req2"


 <form:select path="requirements" multiple="true" id="requirements">
    <form:options items="${yourRequirementsAsACollection}" />
 </form:select>
于 2012-12-19T13:24:40.213 回答