Search code examples
javajspjakarta-eestruts

how to use jsp tag expression in <html:select>?


I want to display dropdown on the basis of if condition,My code snippet is as below

 <%if(userType.equalsIgnoreCase("O")) {String user=(String)session.getAttribute("executorname"); %>
            <html:select style="width:190;" value="<%=user%>" property="jobOwner">
                <html:option value="<%=user %>"><%=user %></html:option>
            </html:select>
            <%} %>

I get org.apache.jasper.JasperException: /jsp/frmQueryExecutor.jsp(73,23) quote symbol expected

I want the value os session variable in dropdown.


Solution

  • Try it this way,

    <c:choose>
      <c:when test="${not empty sessionScope.executorname}"> //if loop
         <html:select style="width:190;" value="<%=user%>" property="jobOwner">
             <html:option value="${sessionScope.executorname}"><${sessionScope.executorname}></html:option>
         </html:select>
      </c:when>
      <c:otherwise> // else loop
          //do whatever
      </c:otherwise>
    </c:choose>
    

    and try to avoid scriplets all together.