<%-- 可以获取对象的属性值 --%>
<%
User entity = new User();
request.setAttribute("user",entity);
%>
<br/>
${user.edu}
<%--可以获取bean中的bean的 中的bean的中的.....属性
${user.address.city.name}
--%>
<br/>
<%--获取List集合中值
<%
List list = new ArrayList();
list.add("oooo1");
list.add("oooo2");
list.add("oooo3");
list.add("oooo4");
request.setAttribute("list",list);
%>
<br/>
${list[0]}
${list[1]}
${list[2]}
${list[3]}
${list[0].address.city.name }
--%>
<%
List list = new ArrayList();
list.add(new User());
request.setAttribute("list",list);
%>
<br/>
<%--获取Map集合中值 --%>
<%
Map map = new HashMap();
map.put("xxx1","redarmy1");
map.put("xxx2","redarmy2");
map.put("xxx3","redarmy3");
map.put("xxx4","redarmy4");
map.put("xxx5","redarmy5");
request.setAttribute("map",map);
%>
<br/>
${map['0']}
1.普通字符串
request.setAttribute("hello", "hello world");
---------------------------------------------El表达式获取
<li>普通字符串</li><br>
hello(jsp脚本):<%=request.getAttribute("hello") %><br>
hello(el表达式,el表达式的使用方法$和{}):${hello }<br>
hello(el表达式,el的隐含对象pageScope,requestScope,sessionScope,applicationScope,
<br> 如果未指定scope,它的搜索顺序pageScope~applicationScope):${requestScope.hello }<br>
hello(el表达式,scope=session):${sessionScope.hello }<br>
--------------------------------------------页面输出
.普通字符串
hello(jsp脚本):hello world
hello(el表达式,el表达式的使用方法$和{}):hello world
hello(el表达式,el的隐含对象pageScope,requestScope,sessionScope,applicationScope,
如果未指定scope,它的搜索顺序为pageScope~applicationScope):hello world
hello(el表达式,scope=session):
2.结构
Group group = new Group();
group.setName("尚学堂");
User user = new User();
user.setUsername("张三");
user.setAge(18);
user.setGroup(group);
request.setAttribute("user", user);
---------------------------------------------El表达式获取
<li>结构,采用.进行导航,也称存取器</li><br>
姓名:${user.username }<br>
年龄:${user.age }<br>
所属组:${user.group.name }<br>
注意:如果想通过el表达式调用bean中的方法,要写一个get开头并且参数为空的函数才可以调用:
原来的方法:
public boolean checkUsername(request){...}
修改之后:
public boolean checkUsername(request){...}
public boolean getCheckUsername(){
request = ...;
return checkUsername(request);
}
--------------------------------------------页面输出
.结构,采用.进行导航,也称存取器
姓名:张三
年龄:18
所属组:尚学堂
<><><><><><><><><><><><><><><><><><><>
3.map
Map mapValue = new HashMap();
mapValue.put("key1", "value1");
mapValue.put("key2", "value2");
request.setAttribute("mapvalue", mapValue);
---------------------------------------------El表达式获取
<li>输出map,采用.进行导航,也称存取器</li><br>
mapvalue.key1:${mapvalue.key1 }<br>
mapvalue.key2:${mapvalue.key2 }<br>
--------------------------------------------页面输出
.输出map,采用.进行导航,也称存取器
mapvalue.key1:value1
mapvalue.key2:value2
<><><><><><><><><><><><><><><><><><><>
4.字符串数组
String[] strArray = new String[]{"a", "b", "c"};
request.setAttribute("strarray", strArray);
User[] users = new User[10];
for (int i=0; i<10; i++) {
User u = new User();
u.setUsername("U_" + i);
users[i] = u;
}
request.setAttribute("users", users);
---------------------------------------------El表达式获取
<li>输出对象数组,采用[]和下标</li><br>
userarray[3].username:${users[2].username }<br>
--------------------------------------------页面输出
.输出对象数组,采用[]和下标
userarray[3].username:U_2
<><><><><><><><><><><><><><><><><><><>
5.ArrayList
List userList = new ArrayList();
for (int i=0; i<10; i++) {
User uu = new User();
uu.setUsername("UU_" + i);
userList.add(uu);
}
request.setAttribute("userlist", userList);
---------------------------------------------El表达式获取
<li>输出list,采用[]和下标</li><br>
userlist[5].username:${userlist[4].username }<br>
--------------------------------------------页面输出
输出list,采用[]和下标
userlist[5].username:UU_4
<><><><><><><><><><><><><><><><><><><>
6.empty
request.setAttribute("value1", null);
request.setAttribute("value2", "");
request.setAttribute("value3", new ArrayList());
request.setAttribute("value4", "123456");
---------------------------------------------El表达式获取
<li>el表达式对运算符的支持</li><br>
1+2=${1+2 }<br>
10/5=${10/5 }<br>
10 div 5=${10 div 5 }<br>
10%3=${10 % 3 }<br>
10 mod 3=${10 mod 3 }<br>
EL调用bean中的方法:
1 public boolean getCheckUser();
2 HttpServlet request = threadLocal.getRequest;
3 return CheckUser(request );
4 }
首先,把request放到某个能随时取得的地方,如ThreadLocal里面,然后,写一个方法,没有参数,在这个方法中调用你原先的方法,最后,在页面上写:
<c:when test= "${XmlUser.checkUser} ">