zoukankan      html  css  js  c++  java
  • jstl 与 el表达式

    jar下载地址参考:https://blog.csdn.net/qq_30062589/article/details/80224080

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <c:if test="${empty users }">
            aaa
        </c:if>
        <c:if test="${!empty users}">
            bbb
        </c:if>
        <br>
        <c:forEach begin="0" end="5" var="i">
            ${i }<br/>
        </c:forEach>
        <c:forEach items="${applicationScope.users }" var="user">
            ${user.name }<br/>
        </c:forEach>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ page import="cn.sasa.domain.*" %>
        <%@ page import="java.util.*" %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <% 
            request.setAttribute("name", "hi");
            
            MyUser user1 = new MyUser();
            user1.setName("aaa");
            session.setAttribute("user", user1);
            
            MyUser user2 = new MyUser();
            user2.setName("bbb");
            List<MyUser> userList = new ArrayList<MyUser>();
            userList.add(user1);
            userList.add(user2);
            application.setAttribute("users", userList);
            
            out.write("web----"+this.getServletContext().getContextPath());
        %>
        <!-- el表达式从域中取值取值 -->
        <br/>
        ${ requestScope.name }
        <br/>
        ${sessionScope.user.name }
        <br/>
        ${applicationScope.users[0].name }
        ${applicationScope.users[1].name }
        
        <hr/>
        <!-- *全域查找 -->
        <br/>
        ${ name }
        <br/>
        ${user.name }
        <br/>
        ${users[0].name }
        ${users[1].name }
        <br/>
        el_web_-----${pageContext.request.contextPath }
        
    </body>
    </html>
  • 相关阅读:
    bzoj 1093: [ZJOI2007]最大半连通子图
    bzoj 1266 1266: [AHOI2006]上学路线route
    poj 2104 K-th Number
    洛谷 P3313 [SDOI2014]旅行
    cogs 306. [SGOI] 糊涂的记者
    cogs 1164. 跑步
    洛谷 1821: [JSOI2010]Group 部落划分 Group
    洛谷 U3357 C2-走楼梯
    洛谷 P3014 [USACO11FEB]牛线Cow Line
    洛谷 P2982 [USACO10FEB]慢下来Slowing down
  • 原文地址:https://www.cnblogs.com/SasaL/p/10635180.html
Copyright © 2011-2022 走看看