EL表达式

EL表达式
出现的原因:
request.getParameter("key值")
request.getAttribute("key值")
上面两种获取属性值的方式过于繁琐,如果其中返还的是对象还需要进行类型的转换,在进行嵌套使用
使用传统方式获取request对象中的值有一下缺点
1、必须要导入包
2、进行类型的强制转换
3、层次结构比较复杂
 
EL表达式的使用
获取request.getParameter("key值")的值
${param.key值}
获取request.getAttribute("key值")的值
${key值}
name:${param.name}
pwd:${param.pwd}
aa:${aa}
town:${user.address.town}  获取User对象设置的key值为user获取其中属性值名为address的属性对象,获取其中的town属性值
武安:${list[1].address.town} 获取数组对象设置的key值为list下标为1其中属性值名为address的属性对象,获取其中的town属性值
mapvalue:${map.china}
mapUser:${map2.a1.address.town}
 
作用域问题:
<%
    pageContext.setAttribute("key","hello pageContext");
    request.setAttribute("key","hello request");
    session.setAttribute("key","hello session");
    application.setAttribute("key","hello application");
%>
key:${key}
//获取作用最小的当前页的值,如果没有找到当前的key会到-request -session -servletContext
 
pageContext:${pageScope.key} //获取当前页属性名为key值
 
 
request:${requestScope.key}//获取request属性名为key值
 
 
session:${sessionScope.key}//获取session属性名为key值
 
 
application:${applicationScope.key}//获取servletContext属性名为key值
 
 
 
posted @ 2021-08-16 16:23  七七负柒柒  阅读(62)  评论(0)    收藏  举报