如何在jsp中刷新页面后保留组合框选择值

时间:2015-09-21 06:23:50

标签: jsp jstl

我正在使用以下代码在页面刷新后保留组合框中的上一个选定值。请在以下代码中建议错误。当两个变量都来自jsp但在比较时不起作用时,它的工作正常 ctr1 == tractor.tractorid;

<%
ArrayList<DozerSelection> tractorInfoList=     (ArrayList<DozerSelection>)request.getAttribute("tractorInfoList");
 int ctr1=1;
 int ctr2=1
%>
 <c:when test="${tractorInfoList.size() != 0}">
 <p style="float:left;">Tractor Name</p><select name="tractor" onChange="search()">
     <c:forEach items="${tractorInfoList}" var="tractor">

 // in this case working fine 
     <option value="${tractor.tractorname}" ${ctr1 ==ctr2  ? 'selected' : ''}>${tractor.tractorname}</option>

 // in this case not working
  <option value="${tractor.tractorname}" ${ctr1 ==tractor.tractorid  ? 'selected' : ''}>${tractor.tractorname}</option>

    </c:forEach>
    </select>
    </c:when>

0 个答案:

没有答案