1、EL表达式
获取4个内置对象(域)中的数据,或自定义对象中的数据,或数组、集合容器中的数据。可以完成非常简单的运行,但它不能完成循环、复杂的判断等功能。
EL表达式的书写格式:${ 表达式 }
2、获取变量数据
String name="陶士涵";
pageContext.setAttribute("name",name);
%>
取值的方式:${name}
3、获取数组数据
String[] names=;
pageContext.setAttribute("names",names);
%>
取值的方式:${name[0]}
4、获取集合数据
List names=new ArrayList();
names.add("陶士涵");
names.add("张三");
pageContext.setAttribute("names",names);
%>
取值的方式:${names[1]}
Map names=new HashMap();
names.put("name","陶士涵");
pageContext.setAttribute("names",names);
%>
取值的方式:${names['name']} ${names.name }
5、获取javabean数据
Person person=new Person();
person.setName("taoshihan");
pageContext.setAttribute("person",person);
%>
取值的方式:${person.name }
例如:通过bsp获取当前登录人名称与试卷创建人名称是否一致:
String path=request.getContextPath();
String userName=BspUtil.getInstance().getLoginUserName();
pageContext.setAttribute("userName",userName);
%>
删除该题
关闭页面
本文详细介绍了EL表达式如何在Web开发中获取内置对象、自定义对象、数组和集合的数据,并展示了如何通过jsp获取变量、数组和JavaBean的数据,以实现登录验证和页面操作。
56万+

被折叠的 条评论
为什么被折叠?



