您现在的位置是:首页 > 文章详情

JSP EL表达式学习笔记

日期:2018-07-11点击:316
<%@page import="java.util.HashMap"%> <%@page import="java.util.Map"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="hah.*" errorPage="common/zz.jsp" %> <%-- errorPage="common/zz.jsp" --%> <!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=UTF-8"> <title>Insert title here</title> </head> <body> <% String name1="name1"; int name2=111; int[] a=new int[3]; //int xx=10/0;//错误 //out.write(xx); a[1]=3; Student student=new Student("ss",22); request.setAttribute("name1", name1); session.setAttribute("name2", name2); request.setAttribute("intx", a); session.setAttribute("student",student); List<Student> list=new ArrayList<Student>(); list.add(new Student("11",111)); list.add(new Student("22",222)); list.add(new Student("33",333)); request.setAttribute("listx",list); Map<String,Student> map=new HashMap<String,Student>(); map.put("1", new Student("11",111)); map.put("2", new Student("22",222)); map.put("2", new Student("33",333)); pageContext.setAttribute("mapx",map); %> <%-- 注意 <%@ pageisELIgnored="true" %> 表示是否禁用EL语言,TRUE表示禁止.FALSE表示不禁止.JSP2.0中默认的启用EL语言。 --%> <%=pageContext.findAttribute("name2")%> <%-- 等效于${name2 } --%> <%-- ${name } 等价于 <%=pageContext.findAttribute("name")%> --%> EL表达式: ${name1 } <%-- 从指定的域中获取数据 否则它是按照小到大的顺序查找域对象的 pageScoep / requestScope / sessionScope / applicationScope --%> ${sessionScope.name2 } ${intx[1] } ${student.name } - ${student.age } ${student["name"] } -${student["age"] } <br/><!-- 这个比上面那个好 --> <%-- (点相对于调用getXX()方法) <%=((Student)pageContext.findAttribute("student")).getName()%> --%> ${listx[2]["name"] } - ${listx[2].age } <br/> <% for(int i=0;i<list.size();i++){ %> <%=list.get(i).getName() +" | "+list.get(i).getAge()%> <% } %> <br/> <!-- //里面不能放额外的字符串 --> ${listx[1]["name"] }---${listx[1].age } <%-- listx[0]等价于 (中括号相对于调用get(参数)方法) ((List)pageContext.findAttribute("list")).get(0) --%> <br/> ${mapx['1']["name"] } <br/> <%-- ${3>=2 } ${10!=3 } <br/> ${true||false} --%> <% String haha=""; request.setAttribute("haha", haha); %> 判断null:${haha==null } 判断空字符: ${haha=="" }<br/> 判空:${haha==null||haha=="" } 另一种判空: ${empty haha } </body> </html>
原文链接:https://yq.aliyun.com/articles/609985
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章