在所有jsp中显示下拉选择值

时间:2016-12-01 09:11:08

标签: javascript jquery html angularjs jsp

我有一个带有下拉框的header.jsp作为" Role"。header.jsp是这样的,用于所有其他JSP by include directive.After登录后,登陆页面是一个主页。用户需要从下拉框中选择一个值,并在此基础上显示一些页面。问题是,当列表中的任何其他jsp进行时,下拉列表中的选定值将被刷新。所有静态数据都被正确地传递给另一个JSP& s.how可以是持久化的值。这段代码(header.jsp)如下所示

<div class='header'>    
    <div class='top_header text-center'>
        <span>Welcome:</span>
        <c:out value="${sessionScope.displayName}" />
        &nbsp;|&nbsp; <span>Role:</span>                        
        <select id="role" class="role_select" name="role" onchange="submitRole(this);">
            <option id="roleOption" value="Select Role">Select Role</option>
        <c:forEach var="role" items="${sessionScope.role}">                     
            <option value='${role}'>                    
                <c:out value="${role}"/>
                <c:set var="SelectRole" scope="session" value="${role}" />                  
            </option>
        </c:forEach>                        
        </select>

        &nbsp;|&nbsp; <span><a href='logout'>Logout</a></span> <span>
            <c:if test="${not empty error}">
                <div>${error}</div>
            </c:if> <c:if test="${not empty message}">
                <div>${message}</div>
            </c:if>
        </span>
    </div>

    <div class='container'>
        <div class='pull-left col-lg-6 col-md-6 col-sm-6 col-xs-6'>
            <span>Feedback System</span>
        </div>
    </div>
 </div>

1 个答案:

答案 0 :(得分:2)

You have to read that value of the selected role and and set it into either the request.setAttribute("SelectRole", "value")
or in session.setAttribute("SelectRole", "value") and in the option tag do the following

<option value="${role}" ${role == SelectRole?'selected="selected"':''}>${role}</option>