如何在jsp,spring,jquery中提交表单后的下拉列表中保留所选值?

时间:2017-07-02 17:17:26

标签: jquery spring jsp

行驶的List.jsp

...
<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脚本,以便在根据过去的脚本提交表单后在下拉列表中保留所选值。它不起作用。

你能跟我说话吗?

1 个答案:

答案 0 :(得分:0)

您可以在会话对象中保留该值,并在需要时检索它。