首页 > 代码库 > 在JSP页面用EL表达式获取数据
在JSP页面用EL表达式获取数据
<h4>获取域对象中的值</h4>
<%
request.setAttribute("name", "射雕英雄传");
application.setAttribute("name", "鹿鼎记");
%>
${requestScope.name }
${applicationScope.name }
<h4>获取数组中的值</h4>
<%
String [] strs={"陆小凤","叶孤城","西门吹雪","李寻欢"};
request.setAttribute("strs", strs);
%>
${strs[1] }
<h4>获取集合中的值</h4>
<%
List<String> list=new ArrayList<String>();
list.add("周芷若");
list.add("小昭");
list.add("赵敏");
list.add("蛛儿");
request.setAttribute("list", list);
%>
${list[2] }
<h4>获取Map中的值</h4>
<%
Map<String,String> map=new HashMap<String,String>();
map.put("A", "东邪");
map.put("B", "西毒");
map.put("C", "南帝");
map.put("D", "北丐");
request.setAttribute("map", map);
%>
${map[‘B‘] }
${map.C }
<h4>获取集合中对象的值</h4>
<%
List<User2> uList=new ArrayList<User2>();
uList.add(new User2("刘备","147"));
uList.add(new User2("关羽","258"));
uList.add(new User2("张飞","369"));
request.setAttribute("uList", uList);
%>
${uList[1].username }
${uList[1].password }
在JSP页面用EL表达式获取数据