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>
谢谢你的回答。这对我不起作用,但你给了我一个很好的提示。谢谢你的回答。这对我不起作用,但你给了我一个很好的暗示。