EL表达式的作用与限制条件

限制条件

  只能访问域对象的数据

用法

  访问基本数据类型

    首先把数据保存在域对象

      pagecontext.setAttribute("name","eric");

    取处对象

       ${name}

  访问引用数据类型

    输出对象的属性值

       class Student{

          private String name;

          private String id ;

        public String getName(){

            return this.name;        

          }

        public String getId(){

            return this.id;        

          }

        }

    在jsp页面中执行以下代码

     Student student = new Studet();//创建对象

     pagecontext.setAttribute("student","student");//保存到域对象中

     ${student.name}  --${student.id}    //点 代表的是get然后把name首字母大写(调用方法)等价于((Student)pagecontext.findAttribute("student").getName())

     

    输出集合对象

      list集合

        List list = new ArrayList();

        list.add(new Strdent("张三","001"));

        ${list[0].name}-${list[0].id}

        中括号相当于调用getxxx方法本例相当于pagecontext.findAttribute("list").get(0);

      map集合

        Map map = new TreeMap();

        map.put("1000",new Strdent("张三","001"));

        pagecontext.setAttribute("map",map);

        ${map['1000'].name}-${map['1000'].id};

          传入一个key值

进行算术和比较运算${写入表达式}

  判空的时候也可以用${empty 值}等价于${值==null}

原文地址:https://www.cnblogs.com/hello-liyb/p/7709642.html