Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Spring MVC+;JSP,从下拉菜单中获取所选值_Jsp_Spring Mvc_Drop Down Menu_Jsp Tags - Fatal编程技术网

Spring MVC+;JSP,从下拉菜单中获取所选值

Spring MVC+;JSP,从下拉菜单中获取所选值,jsp,spring-mvc,drop-down-menu,jsp-tags,Jsp,Spring Mvc,Drop Down Menu,Jsp Tags,我有这一页: <form method="post" action="/monitor/admin/transferDevice/${device.deviceId}" > <input type="submit" value="Transfer Device"> </form> <form:select path="users"> <option value="">Select</opt

我有这一页:

    <form method="post" action="/monitor/admin/transferDevice/${device.deviceId}" >
        <input type="submit" value="Transfer Device">
    </form>

<form:select path="users">
    <option value="">Select</option>
    <c:forEach var="theUser" items="${users}">
        <form:option value="${theUser.userId}"><c:out value="${theUser.name} ${theUser.surname}"/></form:option>
    </c:forEach>
</form:select>

所以这个问题看起来很简单,但对我来说不是。当我按下按钮时,如何将所选用户传递给我的控制器方法?

我不熟悉表单标记,使用它工作吗

@RequestMapping(value = "/admin/transferDevice/{deviceId}", method = RequestMethod.POST)
public String transferForDevice(@PathVariable("deviceId") int deviceId, @RequestParam("users") String user) throws Exception {

也许你的表单结束标签应该在表单下:选择结束标签。

我不熟悉表单标签,使用它工作吗

@RequestMapping(value = "/admin/transferDevice/{deviceId}", method = RequestMethod.POST)
public String transferForDevice(@PathVariable("deviceId") int deviceId, @RequestParam("users") String user) throws Exception {

也许你的表单结束标签应该在表单下:选择结束标签。

我找到了问题的解决方案。下面是我的更新页面:

<form:form modelAttribute="selectedUser" method="POST" action="/monitor/admin/transferDevice/${device.deviceId}" style="width: 310px;">
   <input type="submit" value="Transfer Device" style="height: 68px; width: 197px; ">
        <tr>
            <td>User:</td>
            <td><form:select path="userId">
                <form:option value="0" label="--- Select ---" />
                <c:forEach var="theUser" items="${users}">
                    <form:option value="${theUser.userId.toString()}"><c:out value="${theUser.name} ${theUser.surname}"/></form:option>
                </c:forEach>
                </form:select>
            </td>
        </tr>
</form:form>

我找到了问题的解决办法。下面是我的更新页面:

<form:form modelAttribute="selectedUser" method="POST" action="/monitor/admin/transferDevice/${device.deviceId}" style="width: 310px;">
   <input type="submit" value="Transfer Device" style="height: 68px; width: 197px; ">
        <tr>
            <td>User:</td>
            <td><form:select path="userId">
                <form:option value="0" label="--- Select ---" />
                <c:forEach var="theUser" items="${users}">
                    <form:option value="${theUser.userId.toString()}"><c:out value="${theUser.name} ${theUser.surname}"/></form:option>
                </c:forEach>
                </form:select>
            </td>
        </tr>
</form:form>

谢谢你的回答。这对我不起作用,但你给了我一个很好的提示。谢谢你的回答。这对我不起作用,但你给了我一个很好的暗示。