0
旅行的List.jsp如何在jsp,spring,jquery中提交表单后在下拉菜单中保留选定的值?
...
<body>
<jsp:include page="../Admin/navbar.jsp"/>
<div class="container table-responsive">
<div class="row">
<div class="form-inline">
<form class="form-inline" action="${contextPath}/admin/selectUser" id="selectUserForm">
<div class="form-group">
<label class="control-label" for="selectbasic">Kullanıcı</label>
</div>
<div class="form-group">
<select name="userId" id="user_list"></select>
</div>
</form>
</div>
</div>
当值发生变化,这个脚本运行和页面被重定向到控制器:
---脚本---
....
$('#user_list').on('change', function(e) {
if($('#user_list').val() !='0') {
$(this).closest('form').trigger('submit')
}
});
AdminController.jsp
....
@RequestMapping(value = "/selectUser", method = RequestMethod.GET )
public String getTravelByUserId(@RequestParam("userId") Long theId, Model theModel) {
System.out.println("AdminController.getTravelByUserId");
// get travels from the service
List<Travel> travelList=travelService.getTravelByUserId(theId);
//add the user which authenticatedAdmin to the model
theModel.addAttribute("authenticatedAdmin",authenticationService.getAuthenticatedAdmin().getUsername());
theModel.addAttribute("selectedUser", theId);
// add the users to the model
theModel.addAttribute("travels", travelList);
return "Admin/travel-list";
}
我已经通过selectedUser将选定的值存储在模型Atrribute中。
我写了很多jquery脚本来保留选择的值在表单根据过去脚本提交后的下拉列表中。它没有工作。
你能帮我吗?
首先确保您使用POST方法将表单发送到服务器,POST处理程序在哪里?看不到它。 –
我相信我不使用POST方法.Evertyhing是好的只有问题是保留在下拉列表中选定的值。 – kafkas