EL_获取域中存储的值_List集合&Map集合值

  • List集合:$
    • 例如 $
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <%
        ArrayList<String> list = new ArrayList<String>();
        list.add("aaa");
        list.add("bbb");

        request.setAttribute("list",list);
    %>


    ${list}<br><br><br>

    <hr>

    ${list[0]}<br><br><br>
    ${list[1]}<br><br><br>

    <hr>

    ${requestScope.list.get(0)}<br><br><br>
    ${requestScope.list.get(1)}<br><br><br>

    <hr>

    ${requestScope.list[1]}<br><br><br>
    ${requestScope.list[0]}<br><br><br>

</body>
</html>
  • Map集合:$
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <%
        HashMap<String, String> map = new HashMap<>();
        map.put("name","张三");
        map.put("age","14");

        request.setAttribute("map",map);
    %>


    ${requestScope.map}<br><br>
    ${map}<br><br>

    ${map.name}<br><br>
    ${map.age}<br><br>

    ${requestScope.map.name}<br><br>
    ${requestScope.map.age}<br><br>

    



</body>
</html>
posted @ 2022-08-16 15:04  我滴妈老弟  阅读(15)  评论(0编辑  收藏  举报