EL表达式与隐式对象,实现前台从后台取值
2017-01-04 09:43
218 查看
EL表达式强大的功能在于在js、jsp页面中直接访问服务器作用域,非常的简洁高效,作用域存储数据的格式为key/value的键值对,在EL表达式中key,则可以取出对应的value值
1、EL表达式直接访问相应的作用域,访问的格式为:${作用域.对象}
2、如果不指定访问的作用域,则访问顺序为:Page、Request、Session、Application范围查找(范围从小到大),访问格式为:对象,{user}、user.name,例如:<{user.addr}
(user为一个变量,在action或者severlet中存放于指定的作用域中,addr为user的属性)
3、EL表达式中的隐式对象,方便的获取作用域中特定的参数值,包括:
4、使用pageContext对象取得请求地址的详细信息:
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.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},取得主机端的服务信息
相关文章推荐
- EL表达式与隐式对象,实现前台从后台取值
- Struts2+JQuery+JSON实现异步交互,包括从后台获得单个值、对象、List和Map数据并从前台的表达中获取值
- 关于前台获取到的后台json对象取值时undefined的解决方法
- 后台返回的json对象,前台取值
- Jsp隐式对象和EL表达式隐式对象
- 不用AJAX实现前台JS调用后台C#方法(小技巧) 【改自Web.网际浪人.Blog】
- 将后台数据读取到前台的EXCEL文件中去,用javascript实现.(发一个原创)
- 将后台数据读取到前台的EXCEL文件中去,用javascript实现,asp.net,javacript(发一个原创)
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- 大家很容易忽视的几个问题,1.投简历请换位思考、2.前台页面设计比后台实现更值钱
- asp.net通过反射技术实现Ajax(2)--前台javascript封装的Ajax对象
- 后台调用前台javascript方法报错:“缺少对象”的解决方法
- 利用JS动态创建html控件并在后台实现取值
- 不用AJAX实现前台JS调用后台C#方法(小技巧)-转
- 不用AJAX实现前台JS调用后台C#方法(小技巧) 【改自Web.网际浪人.Blog】
- 转:不用AJAX实现前台JS调用后台C#方法(小技巧)
- 使用反映实现前端WEB窗口控件与后台数据库类对象的动态绑定
- 如何实现在后台调用前台的javascript函数
- JSF如何在后台获得前台页面的标签对象
- 不用AJAX实现前台JS调用后台C#方法