• EL表达式-例子


    <%@page import="java.util.*"%>
    <%@page import="java.util.ArrayList"%>
    <%@page import="java.util.List"%>
    <%@page import="com.amos.model.*"%>
    <%@ page isELIgnored="false"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>el表达式学习</title>
    </head>
    <body>
        第一种,简单取值:
        <%
        String data = "hi,amos!";
        request.setAttribute("data", data);
    %>
        ${data}
        <br> 第二种,从bean中取值:
        <%
            Person p = new Person();
            p.setName("amosli");
            session.setAttribute("person", p);
        %>
        ${person.name}
        <br>
        <%=((Person) session.getAttribute("person")).getName()%><br>
        第三种:从复杂bean中取值:
        <%
            Person person1 = new Person();
            Address a = new Address();
            a.setCity("上海");
            person1.setAddress(a);
            application.setAttribute("p1", person1);
        %>
        ${p1.address.city}
        <br> 第四种:从集合中取值:
        <%
            List list = new ArrayList();
            list.add(new Person("amos"));
            list.add(new Person("li"));
            list.add(new Person("amosli"));
            list.add(new Person("hi"));
            list.add(new Person("hi_amos"));
            application.setAttribute("personlist", list);
        %>
        ${personlist[0].name }
        <br>
    
        <%
            Map map = new HashMap();
            map.put("aa", new Person("aaaa"));
            map.put("cc", new Person("cccc"));
            map.put("dd", new Person("dddd"));
            map.put("ee", new Person("eeee"));
            map.put("11", new Person("111"));
    
            request.setAttribute("map", map);
        %>
        ${map.dd.name }<br> 
        <%-- ${map.11.name } 一般情况下用点号进行取值,如果点号取不出来值,那么可以用[]来代替. --%>
        ${map['11'].name }<br>
        
        获取当前应用的名称:
        ${pageContext.request.contextPath }
        
    </body>
    </html>
  • 相关阅读:
    python中的面向对象编程
    python global vs nonlocal (2)
    python3 nonlocal vs global
    poj蚂蚁问题
    C/C++ static vs global
    砝码问题
    Wythoff's game
    C++中的::operator new, ::operator delete
    客户信息表 自我汇总 待确认
    Oracle Savepoint
  • 原文地址:https://www.cnblogs.com/HD/p/3630152.html
Copyright © 2020-2023  润新知