JSTL表达式在JSP页面中的一些应用

逐渐建立自己的知识库,每次用到一些以前忘记或者是不常用的知识捡起来的同时记录下来,方便自己随时查看,也方便一些恰好有需要的人

1.Jsp引用JSTL标签

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

2.循环渲染表格添加数据

<c:forEach items="${student_Infos}" var="s">
    <tr>
        <td style="text-align: center; vertical-align: middle;">${s.student_id}</td>
        <td style="text-align: center; vertical-align: middle;">${s.student_name}</td>
        <td style="text-align: center; vertical-align: middle;">${s.sex}</td>                                                    
    </tr>
</c:forEach>

3.if判断条件

<c:if test="${student_Info.sex == '男'}">
    <option value="男" selected="selected">男</option>
    <option value="女">女</option>
</c:if>

4.相当于if-else的choose-when-otherwise

<c:forEach items="${department_Infos}" var="s">
    <c:choose>
        <c:when test="${s.department_id == entry_Info.department_id}">
            <option value="${s.department_id}" selected="selected">${s.department_name}</option>
        </c:when>
        <c:otherwise>
            <option value="${s.department_id}">${s.department_name}</option>
        </c:otherwise>
    </c:choose>
</c:forEach>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章