首页 javaWEB JSP常用的jstl标签 C标签,经常用的总结

JSP常用的jstl标签 C标签,经常用的总结

工作中需要用的 在JSP页面中声明JSTL标签: 核心标签库 <%@ taglib uri=”http://jav…

工作中需要用的
在JSP页面中声明JSTL标签: 核心标签库

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<%@taglib prefix="i18n" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/function"%>

流程控制:if,choose,when,otherwise

<c:if test="(这里放一个EL表达式)">xx</c:if>

<c:if test="${item.typeString eq kind}">javaweb.top</c:if>

 

<c:if test="${!empty param.color}">
    <c:choose>
        <c:when test="${param.color == 'red'}">
            <table bgcolor="red"><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>
        </c:when>
        <c:when test="${param.color == 'yellow'}">
            <table bgcolor="yellow"><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>
        </c:when>
        <c:when test="${param.color == 'blue'}">
            <table bgcolor="blue"><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>
        </c:when>
        <c:otherwise>
            <h2>No choice</h2>
        </c:otherwise>
    </c:choose>
</c:if>

迭代:forEach

 

遍历集合

<c:forEach var="i" items="${collection}" varStatus="index">

    ${i} ${index.count}  <!--i为集合中单个元素,index为循环状态 -->

</c:forEach>

 

遍历Map

<c:forEach var="m" items="${map}">

  key=${m.key},value=${m.value}

</c:forEach>

 

打印1到10

<c:forEach var="i" begin="1" end="10" step="1">

  ${i}

</c:forEach>

 

简单例子

<%@page import="tarena.jstl.Student,java.util.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
    Collection students = new ArrayList();
    students.add(new Student("001","zhangsan",23));
    students.add(new Student("002","lisi",22));
    students.add(new Student("003","wangwu",21));

    request.setAttribute("stus", students);
%>
<table border="1">
<c:forEach var="stu" items="${stus}">
    <tr><td>${stu.id}</td>
        <td>${stu.name}</td>
        <td>${stu.age}</td>
    </tr>
</c:forEach>
</table>
<h2>
<%
    Map stus = new HashMap();
    stus.put("001", new Student("001","zhangsan",23));
    stus.put("002", new Student("002","lisi",22));
    stus.put("003", new Student("003","wangwu",21));

    request.setAttribute("stumap", stus);
%>
<c:forEach var="stu" items="${stumap}">
    ${stu.value.id} ${stu.value.name} ${stu.value.age}<br>
</c:forEach>
<hr>
<c:forEach items="${stus}" varStatus="status">
    ${status.count} ${status.current.name} ${status.current.age}<br>
</c:forEach>
<hr>
<c:forEach var="i" begin="0" end="2" step="1">
    No.${i} ${stus[i].id} ${stus[i].name} ${stus[i].age}<br>
</c:forEach>
</h2>
</c:forEach>

 

其他参考

http://www.cnblogs.com/hongten/archive/2011/05/14/2046005.html

免责声明:文章内容不代表本站立场,本站不对其内容的真实性、完整性、准确性给予任何担保、暗示和承诺,仅供读者参考,文章版权归原作者所有。如本文内容影响到您的合法权益(内容、图片等),请及时联系本站,我们会及时删除处理。

为您推荐

nodejs 整理记录

nodejs 整理记录

下载包 https://blog.csdn.net/m0_59878114/article/details/120274...
websocket测试html

websocket测试html

<!DOCTYPE html> <html> <head> <meta cha...
bigdemical两个数比较大小

bigdemical两个数比较大小

/*int result = bigdemical1.compareTo(bigdemical2) result = -...
Beetl2.7 中文文档

Beetl2.7 中文文档

Beetl目前版本是2.7.23,相对于其他java模板引擎,具有功能齐全,语法直观,性能超高,以及编写的模板容易维护等...
纯CSS实现多个便签在一行展示,拖动滚动

纯CSS实现多个便签在一行展示,拖动滚动

div <h2>请注意需要在移动端预览,PC端拖拽无效果</h2> <div class=...
返回顶部