【问题标题】:Display dropdown selected value in all the jsp在所有jsp中显示下拉选择的值
【发布时间】:2016-12-01 09:11:07
【问题描述】:

我有一个带有下拉框的 header.jsp 作为“角色”。header.jsp 是通过 include 指令在所有其他 JSP 中使用的。登录后登录页面是一个主页。用户needs to select a value from the drop down box and some pages appear on that basis.The issue is that the selected value from the drop down is refreshed when any of the other jsp's from the list is selected.All the static data are properly passed到其他 JSP 的.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>

【问题讨论】:

    标签: javascript jquery html angularjs jsp


    【解决方案1】:
    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>  
    

    【讨论】:

    • 谢谢。这行得通,但是在执行此操作后,登陆页面时未选择默认选项值(选择角色)。代码如下&lt;select id="role" class="role_select" name="role" onchange="submitRole(this);"&gt; &lt;option id="roleOption" value="Select Role"&gt;Select Role&lt;/option&gt; &lt;c:forEach var="role" items="${sessionScope.role}"&gt; &lt;option value='${role}' ${role == role?'selected="selected"':''}&gt; ${role} &lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt;
    • 添加默认值
    • 添加默认值空白处。
    猜你喜欢
    • 2018-12-29
    • 2016-12-04
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 2018-04-05
    相关资源
    最近更新 更多