EL表达式

1.基本格式:${}
2.4种取值范围:pageScope,requestScope,sessionScope,applicationScope,只能适用于这4中范围

注意:在struts2中将数据放在OnglValueStack root对象下,但是可以通过EL表达式获取其内值,是因为在struts2中进行了封装EL表达式,添加如果在request中获取不好,就去ValueStack中查找

public class StrutsRequestWrapper extends HttpServletRequestWrapper {
public
Object getAttribute(String key) { if (key == null) { throw new NullPointerException("You must specify a key value"); } if (disableRequestAttributeValueStackLookup || key.startsWith("javax.servlet")) { // don't bother with the standard javax.servlet attributes, we can short-circuit this // see WW-953 and the forums post linked in that issue for more info return super.getAttribute(key); } ActionContext ctx = ActionContext.getContext(); Object attribute = super.getAttribute(key); if (ctx != null && attribute == null) { boolean alreadyIn = isTrue((Boolean) ctx.get(REQUEST_WRAPPER_GET_ATTRIBUTE)); // note: we don't let # come through or else a request for // #attr.foo or #request.foo could cause an endless loop if (!alreadyIn && !key.contains("#")) { try { // If not found, then try the ValueStack ctx.put(REQUEST_WRAPPER_GET_ATTRIBUTE, Boolean.TRUE); ValueStack stack = ctx.getValueStack(); if (stack != null) { attribute = stack.findValue(key); } } finally { ctx.put(REQUEST_WRAPPER_GET_ATTRIBUTE, Boolean.FALSE); } } } return attribute; } }

 

${requestScope.user.name}
3.基本运算:.和[] .用于取属性[]用于取Array,List,Map,Set
${requestScope.map['apple']},${requestScope.list[1]}
4.{}里允许的运算:算术运算,关系运算,逻辑运算,empty/not empty空判断
${1+1}
${user.age<18}
${(user.age>18)&&(user.sex=='男')}
${empty user}判断user对象是否为空
5.EL的11个隐含对象
pageContext,param和paramValues,header和headerValues,cookie,initParam和4种取值范围对象
*pageContext可获取jsp的request,response,out,session,config,servletContext等对象
${pageContext.session.uesr}
header
${header.host}
*cookie
${cookie.key}

posted @ 2015-10-11 20:45  W&L  阅读(169)  评论(0编辑  收藏  举报