EL 表达式用美元符号“$”定界,内容包含在一对花括号“{}”中,例如:${expression}。EL 表达式语法很简单,它最大的特点就是使用很方便。
- <jsp:useBean id="dao" scope="page" class="com.UserInfoDao">jsp:useBean>
- <%dao.name;%>
- <%dao.getName();%>
- <jsp:useBean id="dao" scope="page" class="com.UserInfoDao">jsp:useBean>
- ${dao.name}
- ${dao.getName()}
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Insert title heretitle>
- head>
- <body>
- <% String s1 = "Hello!";
- request.setAttribute("s1",s1);
- String s2="Hello!"; //未将 s2 放入域空间,EL 将无法获取
- %>
- <%="${s1}"%>=${s1} <br>
- <%="${s2}"%>=${s2} <br>
-
- body>
- html>
- <%@page import="java.util.List"%>
- <%@page import="java.util.ArrayList"%>
- <%@page import="java.util.HashMap"%>
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Insert title heretitle>
- head>
- <body>
- <% char[] ch = { '1', '2' };
- request.setAttribute("ch", ch); //将字符数组变量 ch 置于 requestScope 域,以便 EL 可以访问。
- String s1 = "Hello,how are you!";
- request.setAttribute("s1", s1);
- List<String> list = new ArrayList<String>();
- list.add("first");
- list.add("second");
- request.setAttribute("list", list);
- HashMap
map1 = new HashMap(); - map1.put(0L, "天翼");
- map1.put(1L, "翼支付");
- request.setAttribute("map1", map1);
- %>
- s1=${s1}<br>
- 字符数组:<%="${ch[1]}"%>=${ch[1]} <br>
- List 集合:<%="${list[1]}"%>=${list[1]}<br>
- Map 集合:<%="${map1[1]}"%>=${map1[1]} <br>
-
-
- body>
- html>