EL(Expression Language)是为了使JSP写起来更加简单。表达式语言的灵感来自于ECMAScript和XPath表达式语言,它提供了在JSP中简化表达式的方法,EL表达式可以嵌入在Jsp内部,减少Jsp脚本的编写,让Jsp的代码更加简化。EL出现的目的是要替代Jsp页面中脚本的编写。
El表达式最重要的作用是从域中取数据
其中最重要的是EL的全域查找
<!-- 使用el表达式 全域查找 -->
${company }
${user.name }
${list[1].name }
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="cn.aynortechnology.domain.*" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- 模拟域中的数据 -->
<%
//往域中存储一个字符串
request.setAttribute("company", "Aynor Heavy Industry");
//往域中存储一个对象
User user = new User();
user.setId(1);
user.setName("aynor");
user.setPassword("20190222**");
session.setAttribute("user", user);
//往域中存储一个集合
List<User> list = new ArrayList<User>();
User user1 = new User();
user1.setId(1);