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}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM