zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    搞笑视频分析---1、老番茄-最强间谍王
    尚学linux课程---11、vim操作命令1
    php开发面试题---php缓存总结
    legend2---17、legend2里面怎么面向对象
    北风设计模式课程---10、创建型的设计模式对比总结
    北风设计模式课程---8、装饰器模式
    Linux下安装Tomcat服务器
    种子软件下载种子慢怎么解决
    php开发面试题---Redis和Memcache区别,优缺点对比
    Make a dent in the universe
  • 原文地址:https://www.cnblogs.com/HD/p/3630152.html
Copyright © 2011-2022 走看看