一、EL简介

1.语法结构
    ${expression}
2.[]与.运算符
    EL 提供.和[]两种运算符来存取数据。
    当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用 []。例如:
        ${user.My-Name}应当改为${user["username"] }---${user.username }
    如果要动态取值时,就可以用[]来做,而.无法做到动态取值。例如:
        ${sessionScope.user[data]}中data 是一个变量
3.变量
    EL存取变量数据的方法很简单,例如:${username}。它的意思是取出某一范围中名称为username的变量。
    因为我们并没有指定哪一个范围的username,所以它会依序从Page、Request、Session、Application范围查找。
    假如途中找到username,就直接回传,不再继续找下去,但是假如全部的范围都没有找到时,就回传null。
    属性范围在EL中的名称
        Page         pageScope-------------pageContext.getAtrribute()
        Request         requestScope-------request.gsetAtrribute()
        Session         sessionScope-------session.getAtrribute()
        Application     applicationScope---application.getAtrribute()
       
二、EL隐含对象
1.与范围有关的隐含对象
与范围有关的EL 隐含对象包含以下四个:pageScope、requestScope、sessionScope 和applicationScope;
它们基本上就和JSP的pageContext、request、session和application一样;
在EL中,这四个隐含对象只能用来取得范围属性值,即getAttribute(String name),却不能取得其他相关信息。

例如:我们要取得session中储存一个属性username的值,可以利用下列方法:
    session.getAttribute("username") 取得username的值,
在EL中则使用下列方法
    ${sessionScope.username}

2.与输入有关的隐含对象
与输入有关的隐含对象有两个:param和paramValues,它们是EL中比较特别的隐含对象。

例如我们要取得用户的请求参数时,可以利用下列方法:
    request.getParameter(String name)
    request.getParameterValues(String name)
在EL中则可以使用param和paramValues两者来取得数据。
    ${param.name}--->request.getParameter(name);
    ${paramValues.name[0]}---request.getParameterValues(name)[0]

3.其他隐含对象

cookie
JSTL并没有提供设定cookie的动作,
例:要取得cookie中有一个设定名称为userCountry的值,可以使用${cookie.userCountry}来取得它。

cookie.getName(userCountry).getValue()

header和headerValues
header 储存用户浏览器和服务端用来沟通的数据
例:要取得用户浏览器的版本,可以使用${header["User-Agent"]}。
另外在鲜少机会下,有可能同一标头名称拥有不同的值,此时必须改为使用headerValues 来取得这些值。

initParam
initParam取得设定web站点的环境参数(Context)
例:一般的方法String userid = (String)application.getInitParameter("userid");
    可以使用 ${initParam.userid}来取得名称为userid

--->  config.getInitParameter(userid);

pageContext
pageContext取得其他有关用户要求或页面的详细信息。
    ${pageContext.request.queryString}         取得请求的参数字符串

${pageContext.request.requestURL}         取得请求的URL,但不包括请求之参数字符串
    ${pageContext.request.contextPath}         服务的web application 的名称
    ${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运算符
1.算术运算符有五个:+、-、*或$、/或div、%或mod
2.关系运算符有六个:==或eq、!=或ne、<或lt、>或gt、<=或le、>=或ge
3.逻辑运算符有三个:&&或and、||或or、!或not
4.其它运算符有三个:Empty运算符、条件运算符、()运算符
    例:${empty param.name}、${A?B:C}、${A*(B+C)}

1.基准路径  < base href="< %=basePath% >" >有base基准路径   跳转的时候就是按基准路径来   如果没有base那么就按照相对路径来跳转<br>

2.jsp中用JAVA程序需要 < % java  % >    注释< %    //  /**/    % >   java程序定义静态属性和方法< %! % ><br>

3. HTML/XML 注释< !-- info    --><br>

4.el表达式 $ {    }<br>

a.el表达式是专门用来取值 <br>

按照由小到大的范围去取值  page< request  <   session  <  application   <br>

attribute===pageContext.getAttribute()< request.getAttribute()<  session.getAtribute()<  application.getAttribute()<br>

param==request.getParameter("")<br>

paramValues=request.getParameterValues("")<br>

$ { message  }=${message }<br>

$ { pageScope.message }  -- PageScope=${pageScope.message }<br>

$ { requestScope.message }--  RequestScope=${requestScope.message }<br>

$ { sessionScope.message }-- SessionScope=${sessionScope.message }<br>

$ { applicationScope.message }--  ApplicationScope=${applicationScope.message }<br>

$ { bean["name"]  }--$  {bean.name }---  bean.name=${bean.name }---${bean["name"] }---arr[]=${arr[0] }<br>

$   {  param.username } --等价--  < %=request.getParameter("username") %><br>

$   {    paramValues.fav[1] } ---等价---  < %=request.getParameterValues("fav")[1] % ><br>

$ {initParam.userid} ---等价this.getInitParameter("encode")---ecode=${initParam.encode}<br>

$  {cookie.username}--- ${cookie.username.value}<br>--

Cookie  cookie=new Cookie("username","godyang");

response.addCookie(cookie);

$ { empty  param.sex ? "no":"yes"  }= ${ empty  param.sex ? "no":"yes"  }<br>

$ {sex  eq "1" ? "男":"女"  }=== ${sex  eq "1" ? "男":"女"  }<br>

5 中文转码

a.  <  a href=second.jsp?username2=平安 > second1< /a>------>< %=new String((request.getParameter("username2")).getBytes("iso-8859-1"),"UTF-8") %><br>

b.  < a href=second.jsp?username2=< %=URLEncoder.encode(URLEncoder.encode("平安"))%>    > second3< /a>

---< %=URLDecoder.decode(request.getParameter("username2")) %><br/>

EL简介的更多相关文章

  1. JSP EL简介

    JSP EL简介:1.语法:    ${expression} 2.[ ]与.运算符    EL 提供“.“和“[ ]“两种运算符来存取数据.     当要存取的属性名称中包含一些特殊字符,如.或?等 ...

  2. JSTL和EL简介

    EL Expression Language,表达式语言,通过操作存在于PageContext等的数据,实现JSP的编写更加简单,单纯使用EL不用引入jar包,只要容器支持即可. EL的隐含对象 EL ...

  3. [原创]java WEB学习笔记37:EL表达式(简介,运算符,自动类型转换,保留字,隐含对象)

    1.EL 简介 1)EL 全名为 Expression  Language,它原本是 JSTL  1.0 为方便存取数据所自定义的语言 2)语法:EL 语法很简单,它最大的特点就是使用上很方便:${s ...

  4. [转]EL表达式和JSTL表达式实例

    /* **Title:EL表达式和JSTL表达式实例 **Author:Insun **Blog:http://yxmhero1989.blog.163.com/ */ 为了方便写JSP,我们引入了E ...

  5. EL和JSTL专题

    EL简介 EL全名为Expression Language,它原本是JSTL 1.0为方便存取数据所自定义的语言.当时只能在JSTL标签中使用,如下: <c:out value="${ ...

  6. JSP EL表达式(转)

    一.EL简介 1.语法结构     ${expression}2.[]与.运算符     EL 提供.和[]两种运算符来存取数据.    当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字 ...

  7. 【转】EL表达式 (详解)

    EL表达式      1.EL简介 1)语法结构        ${expression} 2)[]与.运算符      EL 提供.和[]两种运算符来存取数据.      当要存取的属性名称中包含一 ...

  8. 【概念笔记】 EL表达式

    一.EL简介 1.语法结构  ${expression} 2.[]与.运算符  EL 提供.和[]两种运算符来存取数据. 当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要 ...

  9. EL表达式 (详解)

    L表达式      1.EL简介 1)语法结构        ${expression} 2)[]与.运算符      EL 提供.和[]两种运算符来存取数据.      当要存取的属性名称中包含一些 ...

随机推荐

  1. OC基础--Hello Shit

    /*  Foundation.h为主头文件, 主头文件中又拷贝了该工具箱中所有工具的头文件, 我们只需要导入主头文件就可以使用该工具箱中所有的工具, 避免了每次使用都要导入一个对应的头文件  工具箱的 ...

  2. enmo_day_10

    RMAN 创建备份集 : backup as backupset format ‘/backup/df_%d_%s_%p/bus’ tablespace hr_data; 创建镜像副本 :(备份慢,恢 ...

  3. megapix-image插件 使用Canvas压缩图片上传 解决手机端图片上传功能的问题

    最近在弄微信端的公众号.订阅号的相关功能,发现原本网页上用的uploadify图片上传功能到手机端有的手机类型上就不能用了,比如iphone,至于为啥我想应该不用多说了吧(uploadify使用fla ...

  4. shell多行注释

    :<<BLOCK ....被注释的多行内容 BLOCK :<< 'BLOCK ....被注释的多行内容 BLOCK'

  5. NSAssert的使用

    NSAssert的使用   苹果在foundation.framework中定义了这么一个宏: #define NSAssert(condition, desc, ...)   第一个参数为一个条件判 ...

  6. java EE实现动态SQL的

    结果图 情况一:

  7. inline-block

    在CSS中,块级对象元素会单独占一行显示,多个block元素会各自新起一行,并且可以设置width,height属性:而内联对象元素前后不会产生换行,一系列inline元素都在一行内显示,直到该行排满 ...

  8. 12-2 mysql 查询

    老师提纲 1. create database test2. drop database test3. create table info( code int primary key, name va ...

  9. PHP操作Excel – PHPExcel 基本用法详解

    导出excel属性设置//Include classrequire_once('Classes/PHPExcel.php');require_once('Classes/PHPExcel/Writer ...

  10. hdu4497 GCD and LCM ——素数分解+计数

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4497 如果G%L != 0,说明一定无解. 把K = G / L质数分解,G / L = p1^t1 ...