User.java
/**
*
*/
package com.bjpowrnode.jstl;
/**
* @ClassName:User
* @Description:TODO
* @author wm
* @date 2016年2月15日上午9:42:15
*/
public class User {
private String username1;
private int age;
private Group group;
public String getUsername() {
return username1;
}
public void setUsername(String username1) {
this.username1 = username1;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
}
JSP
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<h1>测试EL表达式</h1>
<hr>
<li>普通字符串</li><br>
hello(jsp脚本):<%=request.getAttribute("hello") %></br>
hello(El表达式:语法:$和{}:${hello}<br>
hello(el表达式,el内置对象, pageScope,requestScope,sessionScope,applicationScope )<br>
如果不指定范围,它的搜索范围就是pageScope~applicationScope():${requestScope.hello}<br>
hello(el表达式,从session中取得):${sessionScope.hello}<br>
<p>
<li>结构</li>
姓名:${user.username}<br>
年龄:${user.age }<br>
所属:<br>
</body>
</html>
username可以读取到结果,读取的时候,读取的是getUsername,而不是成员变量。
先读取getUsername,然后取get后面的单词,小写。