日期:2014-05-17  浏览次数:20807 次

求这个jsp的简写方法
jsp写法如下:
<c:forEach var="i" begin="1" end="${page.totoalPages}" step="1"> 
        <c:choose>
            <c:when test="${page.currentPage==i}">
                <img src="<%=path%>/images/page/page${i}_selected.jpg" onclick="turnToPage(${i})" style="cursor:pointer;">
</c:when>
<c:otherwise>
    <img src="<%=path%>/images/page/page${i}.jpg" onclick="turnToPage(${i})" style="cursor:pointer;">
        </c:otherwise>
    </c:choose>
</c:forEach>

发现这两个分支只有图片不同,却用 <c:when 写成两个分支,如上:
能不能在图片的src里面做分支,类似下面:
<img srci="if(.....){....}else....." onclick="turnToPage(${i})" style="cursor:pointer;">
的形式~~~~~
求指教!!!

------解决方案--------------------
可以,用条件运算符。
<c:forEach var="i" begin="1" end="${page.totoalPages}" step="1"> 
  <img src="<%=path%>/images/page/page${i}${page.currentPage==i?'_selected':''}.jpg" onclick="turnToPage(${i})" style="cursor:pointer;">        
</c:forEach>