Javaweb入门之jstl表达式

  1. 方法一、EL表达式
    <%
    request.setAttribute(“aaa”,“bbb”);
    %>
    ${aaa}
    方法二、
    <%=request.getAttribute(“aaa”)
    %>
  2. EL表达式
    <%
    request.setAttribute(“aaa”,“bbb”);
    HashMap hashMap = new HashMap<>();
    hashMap.put(“key01”,“value01”);
    hashMap.put(“key02”,“value02”);
    hashMap.put(“key03”,“value03”);
    hashMap.put(“key04”,“value04”);
    request.setAttribute(“hashMap”,hashMap);
    %>
    ${hashMap}
    ${hashMap.get(“key01”)}
    ${15==15&&15>16}
  3. 优先级
    1)根据优先级
    <%
    request.setAttribute(“aaa”,“request”);
    session.setAttribute(“aaa”,“session”);
    %>
    {aaa} 根据优先级取,取request
    2)消除优先级影响
    ${requestScope.aaa}
    ${sessionScope.aaa}
  4. jstl标签
   <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

    <%
        ArrayList<String> strings =new ArrayList<>();
        strings.add("abc");
        strings.add("bc");
        strings.add("cbc");
        strings.add("dbc");
    request.setAttribute("strings",strings);
    %>
    <body>
    <table>
        <c:forEach var="str" items="${strings}">
            <tr>
                <td> ${
     str}</td>
            </tr>
        </c:forEach>
    </table>
    </body>

你可能感兴趣的:(Java基础,jstl)