EL读取Map集合中的参数

本文详细介绍了如何使用EL表达式输出集合在request、session和application三个作用域的不同应用示例,涵盖了集合的创建、设置及访问方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


一、request 范围 print_map.jsp

<%@ page contentType="text/html" pageEncoding="UTF-8" import="java.util.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>EL输出集合</title>
    </head>
    <body>
        <%
            Map map = new HashMap();        // 实例化 List 接口
            map.put("yc", "雨尘");        // 向集合中增加内容
            map.put("etecha", "www.etecha.com");        // 向集合中增加内容
            map.put("email", "914803581@qq.com");    // 向集合中增加内容
            request.setAttribute("info", map);        // 向 request 集合中保存
        %>
        <h3>key 为  的内容:${info["yc"]}</h3>
        <h3>key 为  的内容:${info.etecha}</h3>
        <h3>key 为  的内容:${info.email}</h3>
    </body>
</html>

 

二、session 范围 print_map_session.jsp

<%@ page contentType="text/html" pageEncoding="UTF-8" import="java.util.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>EL输出集合</title>
    </head>
    <body>
        <%
            Map map = new HashMap();        // 实例化 List 接口
            map.put("yc", "雨尘");        // 向集合中增加内容
            map.put("etecha", "www.etecha.com");        // 向集合中增加内容
            map.put("email", "914803581@qq.com");    // 向集合中增加内容
            session.setAttribute("info", map);        // 向 request 集合中保存
        %>
        <h3>key 为  的内容:${info["yc"]}</h3>
        <h3>key 为  的内容:${info["etecha"]}</h3>
        <h3>key 为  的内容:${info.email}</h3>
    </body>
</html>

 

三、application 范围 print_map_application.jsp

<%@ page contentType="text/html" pageEncoding="UTF-8" import="java.util.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>EL输出集合</title>
    </head>
    <body>
        <%
            Map map = new HashMap();        // 实例化 List 接口
            map.put("yc", "雨尘");        // 向集合中增加内容
            map.put("etecha", "www.etecha.com");        // 向集合中增加内容
            map.put("email", "914803581@qq.com");    // 向集合中增加内容
            application.setAttribute("info", map);        // 向 request 集合中保存
        %>
        <h3>key 为  的内容:${info.yc}</h3>
        <h3>key 为  的内容:${info["etecha"]}</h3>
        <h3>key 为  的内容:${info["email"]}</h3>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值