EL的语法:
比如: request.setAttibute("person",Person);
在JSP页面中如何访问person呢?
<html>
<body>
the person is: ${person}
</body>
</html>
如何访问一个对象的属性呢?
比方说一个对象 Person 的 name属性
${person.name}或者${person["name"]}
两者是等价的。
记住"."能做到的,"[]"也能做到。反过来可就不一定了
E表达式:
一、下面是第一个最简单的表达式例子:
建立servlet 文件,名称为:Hello.java 内容如下:
request.setAttribute("hello","hello");
request.getRequestDispatcher("index.ftp").forward(request,response);
建立index.ftp 文件,内容如下:
${hello}
二、作用域的访问对象
pageScope requestScope sessionScope applicationScope
获取的机制如何?
上面ftp的代码改写成:
${requestScope.hello}等价于${hello}
如果明确访问对象,直接到访问对象中找,否则就从最小的作用域开始找直到applicationScope,
最终把结果返回
三、举例说明
先建立实体类
Student.java School.java
1、实例1
Hello.java
Student stu=new Student();
stu.setName("张三");
request.setAttribute("student",stu);
Index.jsp
${requestScope.student["name"]}或${requestScope.student.name}
2、实例2
Hello.java
School school=new School();
Student stu=new Student();
stu.setName("张三");
school.setStudent(stu);
request.setAttribute("school",school);
Index.jsp
${requestScope.school.student["name"]}或${requestScope.school.student.name}
3、实例3