企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 获取域中的数据 必须保证你要获取的数据在JSP的四个域中. ## 获取简单的数据 底层原理是一个map集合. ~~~ <% String[] strs = new String[]{"jack", "milan"}; request.setAttribute("strs", strs); ArrayList<String> list = new ArrayList<>(); list.add("a"); list.add("b"); request.setAttribute("list", list); HashMap<String, String> map = new HashMap<>(); map.put("name", "jack"); map.put("age", "20"); request.setAttribute("map", map); Product product = new Product(1, "电视", 200, "高清"); request.setAttribute("product", product); request.setAttribute("hello,world", "world"); %> 获取数组中的数据: <br> 老方式:<%= ((String[]) request.getAttribute("strs"))[0] %> <br> el方式:${strs[0]} <hr> 获取list中的数据: <br> 老方式:<%= ((List) request.getAttribute("list")).get(0) %> <br> el方式:${list.get(0)} <br> el方式:${list[0]} <hr> 获取map中的数据: <br> 老方式:<%= ((Map<String, String>) request.getAttribute("map")).get("name") %> <br> el方式:${map.get("name")} <br> <hr> 获取bean中的数据: <br> 老方式:<%= ((Product) request.getAttribute("product")).getPname() %> <br> el方式:${product.pname} <br> <hr> 找不到属性怎么办? ${hello} <hr> 属性有特殊符号怎么办? <br> ${requestScope["hello,world"]} //先找域,再用中括号包裹 ~~~