pp_crz_coder

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Express Language: replace the function of <%= ..... %> in JSP.

The grammar of EL: ${ EL content }:

    <%= 1+1 %>  equals ${ 1+1 }

Where to get the data via EL?

  pageContext, request, session, application the four important domain object.

The following is a JavaBean class:

class Person{
  private String name = "pp";
  private String city;

  getter/setter;
}

 

To get the Person class's name String in the JSP:

 <%

  Person p = new Person();

  pageContext.setAttribute("p",p);

%>

name: ${p.name} <%-- the "." means call the getter method fo Person class --%>
name: ${p["name"]} <%-- has the same function --%>

 

 

Get the data in List:

<%
     List<String> list = new ArrayList<String>();
     list.add("aaa");
     list.add("bbb");
     list.add("ccc");
     
     pageContext.setAttribute("list", list);
      %>
      
     List:${list[1] }

 

 

 Get the data in Map:

<%
          Map<String,String> map = new HashMap<String,String>();
          
          map.put("a", "aaa");
          map.put("b", "bbb");
          map.put("c", "ccc");
          
          pageContext.setAttribute("map", map);
       %>
Map:${map.a }

 

 

 .

 

posted on 2017-08-09 20:41  ppcoder  阅读(106)  评论(0编辑  收藏  举报