EL表达式与隐式对象,实现前台从后台取值
2015-12-07 15:40
344 查看
EL表达式强大的功能在于在js、jsp页面中直接访问服务器作用域,非常的简洁高效,作用域存储数据的格式为key/value的键值对,在EL表达式中key,则可以取出对应的value值
1、EL表达式直接访问相应的作用域,访问的格式为:${作用域.对象}
2、如果不指定访问的作用域,则访问顺序为:Page、Request、Session、Application范围查找(范围从小到大),访问格式为:对象,{对象},{user}、user.name,例如:<{user.name},例如:<%=user.getAddr( ) %> 等价于 {user.addr} (user为一个变量,在action或者severlet中存放于指定的作用域中,addr为user的属性)
3、EL表达式中的隐式对象,方便的获取作用域中特定的参数值,包括:
4、使用pageContext对象取得请求地址的详细信息:
5、可以查看我之前的一篇总结:/article/7846084.html
1、EL表达式直接访问相应的作用域,访问的格式为:${作用域.对象}
Page:PageScope,使用方式${ pageScope.page_name } Request:RequestScope,使用方式${ requestScope.request_name },相当于<%=request.getAttribute("request_name");%> Session:SessionScope,使用方式${ sessionScope.session_name },相当于<%=session.getAttribute("session_name");%> Application:ApplicationScope,使用方式${ applicationScope.application_name },相当于<%=application.getAttribute("application_name");%>
2、如果不指定访问的作用域,则访问顺序为:Page、Request、Session、Application范围查找(范围从小到大),访问格式为:对象,{对象},{user}、user.name,例如:<{user.name},例如:<%=user.getAddr( ) %> 等价于 {user.addr} (user为一个变量,在action或者severlet中存放于指定的作用域中,addr为user的属性)
3、EL表达式中的隐式对象,方便的获取作用域中特定的参数值,包括:
${param},将请求参数名称映射到单个字符串参数值,表达式 $(param.name) 相当于 <%=request.getParameter(name) %> ${paramValues},将请求参数名称映射到一个数值数组,表达式 ${paramvalues. name) 相当于 <%=request.getParamterValues(name)%> ${header},储存用户浏览器和服务端用来沟通的数据,表达式 ${header.name} 相当于 <%=request.getHeader(name)%> ${headerValues},有可能同一标头名称拥有不同的值,表达式 ${headerValues.name} 相当于 <%=request.getHeaderValues(name)%> ${cookie},将cookie名称映射到单个cookie对象,表达式 ${cookie.name.value} 返回带有特定名称的第一个cookie 值。如果请求包含多个同名的 cookie,则应该使用 ${headerValues.name} 表达式 ${initParam},将上下文初始化参数名称映射到单个值,表达式 ${initParam.userid} 相当于 <%=application.getInitParameter("userid")%>
4、使用pageContext对象取得请求地址的详细信息:
${pageContext.request.queryString},取得请求的参数字符串,相当于<%=request.getQueryString()%> ${pageContext.request.requestURL},取得请求的URL,但不包括请求之参数字符串,相当于<%=request.getRequestURL()%> ${pageContext.request.contextPath},服务的web application 的名称,相当于<%=request.getContextPath()%> ${pageContext.request.method},取得HTTP 的方法(GET、POST) ${pageContext.request.protocol},取得使用的协议(HTTP/1.1、HTTP/1.0) ${pageContext.request.remoteUser},取得用户名称 ${pageContext.request.remoteAddr },取得用户的IP 地址 ${pageContext.session.new},判断session 是否为新的 ${pageContext.session.id},取得session 的ID ${pageContext.servletContext.serverInfo},取得主机端的服务信息
5、可以查看我之前的一篇总结:/article/7846084.html
相关文章推荐
- JVM工作原理和特点
- UVALive 6834 (线段树)
- 利用媒介查询实现自动缩放字体大小
- 优化UITableView滚动的流畅性
- 页面滚动到底部自动加载下一页功能的实现
- Android通过剪切板传递数据
- python编程基础:《http://www.cnblogs.com/wiki-royzhang/category/466416.html》
- linux常用命令
- VSTO出现An error occurred while signing: 指定了无效的提供程序类型
- Android——蓝牙通信
- 中国计算机学会推荐国际学术刊物 (人工智能与模式识别)
- 12.7 数据仓库课
- getSharedPreferences()与getSharedPreferences()与getDefaultSharedPreferences()的区别
- 状态模式
- 1054. The Dominant Color (20)【水题】——PAT (Advanced Level) Practise
- 无限风光 : 近来地形算法学习小结
- Twitter架构
- CentOS 6.0如何安装配置Kamailio
- 14.15 InnoDB Backup and Recovery Innodb备份和恢复
- 中国计算机学会推荐国际学术期刊 (计算机图形学与多媒体)