在JSP頁面用EL運算式擷取資料

來源:互聯網
上載者:User

標籤:list   對象   ons   string   username   擷取域對象   scope   bsp   cat   

<h4>擷取域對象中的值</h4>
<%
    request.setAttribute("name", "射鵰英雄傳");
    application.setAttribute("name", "鹿鼎記");
%>
${requestScope.name }

${applicationScope.name }

<h4>擷取數組中的值</h4>
<%
    String [] strs={"陸小鳳","葉孤城","西門吹雪","李尋歡"};
    request.setAttribute("strs", strs);
%>
${strs[1] }

<h4>擷取集合中的值</h4>
<%
    List<String> list=new ArrayList<String>();
    list.add("周芷若");
    list.add("小昭");
    list.add("趙敏");
    list.add("蛛兒");
    request.setAttribute("list", list);
%>
${list[2] }

<h4>擷取Map中的值</h4>
<%
    Map<String,String> map=new HashMap<String,String>();
    map.put("A", "東邪");
    map.put("B", "西毒");
    map.put("C", "南帝");
    map.put("D", "北丐");
    request.setAttribute("map", map);
%>
${map[‘B‘] }

${map.C }

<h4>擷取集合中對象的值</h4>
<%
    List<User2> uList=new ArrayList<User2>();
    uList.add(new User2("劉備","147"));
    uList.add(new User2("關羽","258"));
    uList.add(new User2("張飛","369"));
    request.setAttribute("uList", uList);

%>
${uList[1].username }
${uList[1].password }

在JSP頁面用EL運算式擷取資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.